Skip to content

Commit

Permalink
feat: allow hiding pipeline values in validation output
Browse files Browse the repository at this point in the history
- Add a `-q` / `--quiet` flag to support suppressing the pipeline values
  added in CircleCI-Public#855
- Print the config values one line at a time, and add newlines

Fixes CircleCI-Public#860
  • Loading branch information
wyardley committed Mar 8, 2023
1 parent 7602c67 commit 9ee9c17
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 quietOutput bool // Suppress extra diagnostic output

var configAnnotations = map[string]string{
"<path>": "The path to your config (use \"-\" for STDIN)",
Expand Down Expand Up @@ -73,6 +74,7 @@ func newConfigCommand(config *settings.Config) *cobra.Command {
}
validateCommand.Annotations["<path>"] = configAnnotations["<path>"]
validateCommand.PersistentFlags().StringVarP(&configPath, "config", "c", ".circleci/config.yml", "path to config file")
validateCommand.PersistentFlags().BoolVarP(&quietOutput, "quiet", "q", false, "Suppress 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)
Expand Down Expand Up @@ -139,8 +141,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 !(quietOutput) {
printValues(values)
}

orgID, _ := flags.GetString("org-id")
if strings.TrimSpace(orgID) != "" {
Expand Down Expand Up @@ -197,7 +200,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")
Expand Down Expand Up @@ -237,7 +239,8 @@ func migrateConfig(opts configOptions) error {
}

func printValues(values pipeline.Values) {
fmt.Println("Processing config with following values")
for key, value := range values {
fmt.Printf("\t%s:\t%s", key, value)
fmt.Printf("%-18s: %s\n", key, value)
}
}

0 comments on commit 9ee9c17

Please sign in to comment.