diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2023-04-11 12:41:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 12:41:01 +0200 |
commit | 713394b027d243eaf4ee44882910d8e328a811c6 (patch) | |
tree | d1417319d9bb2afbd36ab1400cd0620daae4e466 | |
parent | 76cac280278ffb90678f8fee317929657b2380e1 (diff) | |
parent | 3b951fe237b878d3dacd1b01bc1a9cac802ef6f1 (diff) |
Merge pull request #26704 from vespa-engine/mpolden/respect-flag
Ensure that explicit flag value is always preferred
-rw-r--r-- | client/go/internal/cli/cmd/config.go | 10 | ||||
-rw-r--r-- | client/go/internal/cli/cmd/config_test.go | 1 | ||||
-rw-r--r-- | client/go/internal/cli/cmd/visit_test.go | 2 |
3 files changed, 7 insertions, 6 deletions
diff --git a/client/go/internal/cli/cmd/config.go b/client/go/internal/cli/cmd/config.go index fd049864096..2d32c454842 100644 --- a/client/go/internal/cli/cmd/config.go +++ b/client/go/internal/cli/cmd/config.go @@ -544,12 +544,12 @@ func (c *Config) list(includeUnset bool) []string { } // flagValue returns the set value and default value of the named flag. -func (c *Config) flagValue(name string) (string, string) { +func (c *Config) flagValue(name string) (string, string, bool) { f, ok := c.flags[name] if !ok { - return "", "" + return "", "", ok } - return f.Value.String(), f.DefValue + return f.Value.String(), f.DefValue, f.Changed } // getNonEmpty returns value of given option, if that value is non-empty @@ -564,9 +564,9 @@ func (c *Config) getNonEmpty(option string) (string, bool) { // get returns the value associated with option, from the most preferred source in the following order: flag > local // config > global config. func (c *Config) get(option string) (string, bool) { - flagValue, flagDefault := c.flagValue(option) + flagValue, flagDefault, changed := c.flagValue(option) // explicit flag value always takes precedence over everything else - if flagValue != flagDefault { + if changed { return flagValue, true } // ... then local config, if option is explicitly defined there diff --git a/client/go/internal/cli/cmd/config_test.go b/client/go/internal/cli/cmd/config_test.go index 612904061de..458878b4356 100644 --- a/client/go/internal/cli/cmd/config_test.go +++ b/client/go/internal/cli/cmd/config_test.go @@ -28,6 +28,7 @@ func TestConfig(t *testing.T) { assertConfigCommand(t, configHome, "", "config", "set", "target", "http://127.0.0.1:8080") assertConfigCommand(t, configHome, "", "config", "set", "target", "https://127.0.0.1") assertConfigCommand(t, configHome, "target = https://127.0.0.1\n", "config", "get", "target") + assertConfigCommand(t, configHome, "target = local\n", "config", "get", "-t", "local", "target") // application assertConfigCommandErr(t, configHome, "Error: invalid application: \"foo\"\n", "config", "set", "application", "foo") diff --git a/client/go/internal/cli/cmd/visit_test.go b/client/go/internal/cli/cmd/visit_test.go index 4302680b9d9..b6e5b893e0b 100644 --- a/client/go/internal/cli/cmd/visit_test.go +++ b/client/go/internal/cli/cmd/visit_test.go @@ -47,7 +47,7 @@ func TestQuoteFunc(t *testing.T) { res := quoteArgForUrl(s) if i < 32 || i > 127 { assert.Equal(t, "a+z", res) - } else { + } else if testing.Verbose() { // go test -v fmt.Printf("res %3d => '%s'\n", i, res) } } |