Skip to content

Commit

Permalink
use exec scoped format var
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Jun 24, 2021
1 parent 9289dc0 commit 8751521
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
)

var (
labels []string
labels []string
execFormat string
)

// execCmd represents the exec command
Expand All @@ -35,7 +36,7 @@ var execCmd = &cobra.Command{
fmt.Println("provide command to execute")
return
}
switch format {
switch execFormat {
case "json",
"plain":
// expected values, go on
Expand Down Expand Up @@ -82,7 +83,7 @@ var execCmd = &cobra.Command{
continue
}
contName := strings.TrimLeft(cont.Names[0], "/")
switch format {
switch execFormat {
case "json":
jsonResult[contName] = make(map[string]interface{})
err := json.Unmarshal([]byte(stdout), &doc)
Expand All @@ -102,7 +103,7 @@ var execCmd = &cobra.Command{

}
}
if format == "json" {
if execFormat == "json" {
result, err := json.Marshal(jsonResult)
if err != nil {
log.Errorf("Issue converting to json %v", err)
Expand All @@ -115,5 +116,5 @@ var execCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(execCmd)
execCmd.Flags().StringSliceVarP(&labels, "label", "", []string{}, "labels to filter container subset")
execCmd.Flags().StringVarP(&format, "format", "f", "plain", "output format. One of [json, plain]")
execCmd.Flags().StringVarP(&execFormat, "format", "f", "plain", "output format. One of [json, plain]")
}

0 comments on commit 8751521

Please sign in to comment.