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
- Write to stderr so that outputting to a file won't generate invalid
  YAML when writing files to stdout
Fixes CircleCI-Public#860
  • Loading branch information
wyardley committed Mar 13, 2023
1 parent 7602c67 commit 3aa6bb4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/CircleCI-Public/circleci-cli/api"
Expand All @@ -28,6 +29,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 +75,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 +142,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 +201,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 +240,8 @@ 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)
}
}

0 comments on commit 3aa6bb4

Please sign in to comment.