Skip to content

Commit

Permalink
Additional formatting updates for config validation
Browse files Browse the repository at this point in the history
Resolve some issues from #861 and #896

- Suppress some whitespace when verbose output is not enabled
- Write to stderr again
- Use "%v" instead of "%s" so that "number" in pipeline values gets
  printed correctly
- Sort values to provide stable output order for pipeline values
  • Loading branch information
wyardley committed Apr 5, 2023
1 parent c6fe24f commit cb2d3e6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@ package config
import (
"fmt"
"os"
"sort"
"strings"

"github.com/pkg/errors"
"gopkg.in/yaml.v3"
)

func printValues(values Values) {
for key, value := range values {
fmt.Fprintf(os.Stderr, "%-18s %s\n", key+":", value)
// Provide a stable sort order for printed values
keys := make([]string, 0, len(values))
for k := range values {
keys = append(keys, k)
}
sort.Strings(keys)

for _, key := range keys {
fmt.Fprintf(os.Stderr, "%-18s %v\n", key+":", values[key])
}

// Add empty newline at end
fmt.Fprintf(os.Stderr, "\n")
}

type ProcessConfigOpts struct {
Expand Down Expand Up @@ -73,7 +84,7 @@ func (c *ConfigCompiler) ProcessConfig(opts ProcessConfigOpts) error {
//if no orgId provided use org slug
values := LocalPipelineValues()
if opts.VerboseOutput {
fmt.Println("Processing config with following values")
fmt.Fprintln(os.Stderr, "Processing config with following values:")
printValues(values)
}

Expand Down Expand Up @@ -118,7 +129,7 @@ func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error {
//if no orgId provided use org slug
values := LocalPipelineValues()
if opts.VerboseOutput {
fmt.Println("Validating config with following values")
fmt.Fprintln(os.Stderr, "Validating config with following values:")
printValues(values)
}

Expand Down Expand Up @@ -152,6 +163,6 @@ func (c *ConfigCompiler) ValidateConfig(opts ValidateConfigOpts) error {
}
}

fmt.Printf("\nConfig file at %s is valid.\n", opts.ConfigPath)
fmt.Printf("Config file at %s is valid.\n", opts.ConfigPath)
return nil
}

0 comments on commit cb2d3e6

Please sign in to comment.