Skip to content

Commit 3a47ae9

Browse files
authored
Support option "--output" for command "get chaos-experiments"
1 parent d304f7d commit 3a47ae9

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/cmd/get/experiments.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,27 @@ var experimentsCmd = &cobra.Command{
7676
os.Exit(1)
7777
}
7878
}
79-
80-
outputFormat := ""
81-
outputPrompt := promptui.Select{
82-
Label: "Select an output format",
83-
Items: []string{"table", "json", "yaml"},
84-
}
85-
_, outputFormat, err = outputPrompt.Run()
79+
80+
outputFormat, err := cmd.Flags().GetString("output")
8681
utils.PrintError(err)
82+
83+
if outputFormat == "" {
84+
outputPrompt := promptui.Select{
85+
Label: "Select an output format",
86+
Items: []string{"table", "json", "yaml"},
87+
}
88+
_, outputFormat, err = outputPrompt.Run()
89+
utils.PrintError(err)
90+
}
91+
92+
if outputFormat != "table" && outputFormat != "json" && outputFormat != "yaml" {
93+
outputPrompt := promptui.Select{
94+
Label: "Invalid output format '"+outputFormat+"'. Select a valid output format",
95+
Items: []string{"table", "json", "yaml"},
96+
}
97+
_, outputFormat, err = outputPrompt.Run()
98+
utils.PrintError(err)
99+
}
87100

88101
switch outputFormat {
89102
case "json":
@@ -146,5 +159,5 @@ func init() {
146159
experimentsCmd.Flags().Bool("all", false, "Set to true to display all Chaos experiments")
147160
experimentsCmd.Flags().StringP("chaos-infra", "A", "", "Set the Chaos Infrastructure name to display all Chaos experiments targeted towards that particular Chaos Infrastructure.")
148161

149-
experimentsCmd.Flags().StringP("output", "o", "", "Output format. One of:\njson|yaml")
162+
experimentsCmd.Flags().StringP("output", "o", "", "Output format. One of:\ntable|json|yaml")
150163
}

0 commit comments

Comments
 (0)