From dc43137315f72053725afedf4d7e45574e913b30 Mon Sep 17 00:00:00 2001 From: William Yardley Date: Tue, 7 Mar 2023 16:14:10 -0800 Subject: [PATCH] feat: add verbose flag for pipeline values - Add a `-v` / `--verbose` flag to enable verbose output - Print the config values one line at a time, and add newlines - Write to stderr so that outputting to a file won't generate invalid YAML when writing files to stdout Fixes #860 --- cmd/config.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index a30c82d78..dce808c14 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "net/url" + "os" "strings" "github.com/CircleCI-Public/circleci-cli/api/rest" @@ -33,6 +34,7 @@ type configOptions struct { // Used to for compatibility with `circleci config validate --path` var configPath string var ignoreDeprecatedImages bool // should we ignore deprecated images warning +var verboseOutput bool // Enable extra debugging output var configAnnotations = map[string]string{ "": "The path to your config (use \"-\" for STDIN)", @@ -86,6 +88,7 @@ func newConfigCommand(config *settings.Config) *cobra.Command { } validateCommand.Annotations[""] = configAnnotations[""] validateCommand.PersistentFlags().StringVarP(&configPath, "config", "c", ".circleci/config.yml", "path to config file") + validateCommand.PersistentFlags().BoolVarP(&verboseOutput, "verbose", "v", false, "Enable verbose output") validateCommand.PersistentFlags().BoolVar(&ignoreDeprecatedImages, "ignore-deprecated-images", false, "ignores the deprecated images error") if err := validateCommand.PersistentFlags().MarkHidden("config"); err != nil { panic(err) @@ -153,8 +156,9 @@ func validateConfig(opts configOptions, flags *pflag.FlagSet) error { //if no orgId provided use org slug values := pipeline.LocalPipelineValues() - fmt.Println("Validating config with following values") - printValues(values) + if verboseOutput { + printValues(values) + } var orgID string orgID, _ = flags.GetString("org-id") @@ -217,7 +221,6 @@ func processConfig(opts configOptions, flags *pflag.FlagSet) error { //if no orgId provided use org slug values := pipeline.LocalPipelineValues() - fmt.Println("Processing config with following values") printValues(values) orgID, _ := flags.GetString("org-id") @@ -262,8 +265,9 @@ func migrateConfig(opts configOptions) error { } func printValues(values pipeline.Values) { + fmt.Fprintln(os.Stderr, "Processing config with following values:") for key, value := range values { - fmt.Printf("\t%s:\t%s", key, value) + fmt.Fprintf(os.Stderr, "%-18s %s\n", key+":", value) } }