Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support option "--output" for command "get chaos-experiments" #223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions pkg/cmd/get/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,27 @@ var experimentsCmd = &cobra.Command{
os.Exit(1)
}
}

outputFormat := ""
outputPrompt := promptui.Select{
Label: "Select an output format",
Items: []string{"table", "json", "yaml"},
}
_, outputFormat, err = outputPrompt.Run()

outputFormat, err := cmd.Flags().GetString("output")
utils.PrintError(err)

if outputFormat == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also merge the if statements into one to get rid of repeating promptui code. if == "" &&
Maybe something like input a valid output format

outputPrompt := promptui.Select{
Label: "Select an output format",
Items: []string{"table", "json", "yaml"},
}
_, outputFormat, err = outputPrompt.Run()
utils.PrintError(err)
}

if outputFormat != "table" && outputFormat != "json" && outputFormat != "yaml" {
outputPrompt := promptui.Select{
Label: "Invalid output format '"+outputFormat+"'. Select a valid output format",
Items: []string{"table", "json", "yaml"},
}
_, outputFormat, err = outputPrompt.Run()
utils.PrintError(err)
}

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

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