Skip to content

Commit

Permalink
rework debug printings
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Mar 13, 2019
1 parent 9f3a6b4 commit 65ac310
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 2 additions & 7 deletions cmd/tubectl/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"sort"
Expand Down Expand Up @@ -43,9 +42,7 @@ func requestNamespaces(ctlPath string, params *Params) ([]string, error) {
"get", "namespaces", "-o", "json",
)

if debug {
log.Printf(":: %q", args)
}
debugcmd(args)

ctx := karma.Describe(
"cmdline",
Expand Down Expand Up @@ -85,9 +82,7 @@ func requestResources(ctlPath string, params *Params) ([]Resource, error) {
"get", params.Match.Resource, "-o", "json",
)

if debug {
log.Printf(":: %q", args)
}
debugcmd(args)

ctx := karma.Describe(
"cmdline",
Expand Down
15 changes: 12 additions & 3 deletions cmd/tubectl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func syscallExec(ctlPath string, params *Params) {
args = append(args, arg)
}

if debug {
log.Printf(":: %q", args)
}
debugcmd(args)

syscall.Exec(
ctlPath,
Expand Down Expand Up @@ -191,3 +189,14 @@ func complete(items []string, query string) string {

return partial
}

func debugcmd(args []string) {
if debug {
values := []string{}
for _, arg := range args {
values = append(values, fmt.Sprintf("%q", arg))
}

log.Printf("%s", strings.Join(values, " "))
}
}
5 changes: 1 addition & 4 deletions cmd/tubectl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"log"
"os"
"os/exec"
"sync"
Expand Down Expand Up @@ -77,9 +76,7 @@ func parallelize(tasks []Task) {
}

func run(ctlPath string, args []string, writer io.Writer) error {
if debug {
log.Printf(":: %q", append([]string{ctlPath}, args...))
}
debugcmd(append([]string{ctlPath}, args...))

cmd := exec.Command(ctlPath, args...)
cmd.Stdout = writer
Expand Down

0 comments on commit 65ac310

Please sign in to comment.