Skip to content

Commit

Permalink
Merge pull request #21479 from vespa-engine/mpolden/quiet-config
Browse files Browse the repository at this point in the history
Support setting quiet option through config
  • Loading branch information
mpolden authored Mar 1, 2022
2 parents e87944d + c7b8d8c commit c8efa8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions client/go/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ func (c *Config) Set(option, value string) error {
viper.Set(option, value)
return nil
}
case quietFlag:
switch value {
case "true", "false":
viper.Set(option, value)
return nil
}
case apiKeyFileFlag:
viper.Set(option, value)
return nil
Expand Down
3 changes: 3 additions & 0 deletions client/go/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func TestConfig(t *testing.T) {
assertConfigCommand(t, "", homeDir, "config", "set", "wait", "60")
assertConfigCommandErr(t, "Error: wait option must be an integer >= 0, got \"foo\"\n", homeDir, "config", "set", "wait", "foo")
assertConfigCommand(t, "wait = 60\n", homeDir, "config", "get", "wait")

assertConfigCommand(t, "", homeDir, "config", "set", "quiet", "true")
assertConfigCommand(t, "", homeDir, "config", "set", "quiet", "false")
}

func assertConfigCommand(t *testing.T, expected, homeDir string, args ...string) {
Expand Down
11 changes: 5 additions & 6 deletions client/go/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ func isTerminal() bool {
}

func configureOutput() error {
if quietArg {
stdout = ioutil.Discard
}
log.SetFlags(0) // No timestamps
log.SetOutput(stdout)

config, err := LoadConfig()
if err != nil {
return err
}
if quiet, _ := config.Get(quietFlag); quiet == "true" {
stdout = ioutil.Discard
}
log.SetFlags(0) // No timestamps
log.SetOutput(stdout)
colorValue, _ := config.Get(colorFlag)
colorize := false
switch colorValue {
Expand Down

0 comments on commit c8efa8e

Please sign in to comment.