diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-03-01 10:45:17 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-03-01 10:45:17 +0100 |
commit | b0044b7d1840492a67c27a76860ef9bd40900b02 (patch) | |
tree | fea200594d68bad60ceeebc24eff198de6d9eac9 /client | |
parent | f05709eb4179dc562083409797889770c74a5ef0 (diff) |
Use bool to indicate presence of config value
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/config.go | 19 | ||||
-rw-r--r-- | client/go/cmd/helpers.go | 10 | ||||
-rw-r--r-- | client/go/cmd/root.go | 6 |
3 files changed, 15 insertions, 20 deletions
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go index 0997be2c899..3891ef0524d 100644 --- a/client/go/cmd/config.go +++ b/client/go/cmd/config.go @@ -183,14 +183,14 @@ func (c *Config) X509KeyPair(app vespa.ApplicationID) (KeyPair, error) { } func (c *Config) APIKeyPath(tenantName string) string { - if override, err := c.Get(apiKeyFileFlag); err == nil && override != "" { + if override, ok := c.Get(apiKeyFileFlag); ok { return override } return filepath.Join(c.Home, tenantName+".api-key.pem") } func (c *Config) ReadAPIKey(tenantName string) ([]byte, error) { - if override, err := c.Get(apiKeyFlag); err == nil && override != "" { + if override, ok := c.Get(apiKeyFlag); ok { return []byte(override), nil } return ioutil.ReadFile(c.APIKeyPath(tenantName)) @@ -198,13 +198,12 @@ func (c *Config) ReadAPIKey(tenantName string) ([]byte, error) { // UseAPIKey checks if api key should be used be checking if api-key or api-key-file has been set. func (c *Config) UseAPIKey(system vespa.System, tenantName string) bool { - if _, err := c.Get(apiKeyFlag); err == nil { + if _, ok := c.Get(apiKeyFlag); ok { return true } - if _, err := c.Get(apiKeyFileFlag); err == nil { + if _, ok := c.Get(apiKeyFileFlag); ok { return true } - // If no Auth0 token is created, fall back to tenant api key, but warn that this functionality is deprecated // TODO: Remove this when users have had time to migrate over to Auth0 device flow authentication a, err := auth0.GetAuth0(c.AuthConfigPath(), system.Name, system.URL) @@ -267,12 +266,12 @@ func (c *Config) load() error { return err } -func (c *Config) Get(option string) (string, error) { +func (c *Config) Get(option string) (string, bool) { value := viper.GetString(option) if value == "" { - return "", fmt.Errorf("no such option: %q", option) + return "", false } - return value, nil + return value, true } func (c *Config) Set(option, value string) error { @@ -313,8 +312,8 @@ func (c *Config) Set(option, value string) error { } func printOption(cfg *Config, option string) { - value, err := cfg.Get(option) - if err != nil { + value, ok := cfg.Get(option) + if !ok { value = color.Faint("<unset>").String() } else { value = color.Cyan(value).String() diff --git a/client/go/cmd/helpers.go b/client/go/cmd/helpers.go index ab47a0e6d88..9003a64b33b 100644 --- a/client/go/cmd/helpers.go +++ b/client/go/cmd/helpers.go @@ -123,8 +123,8 @@ func getApplication() (vespa.ApplicationID, error) { if err != nil { return vespa.ApplicationID{}, err } - app, err := cfg.Get(applicationFlag) - if err != nil { + app, ok := cfg.Get(applicationFlag) + if !ok { return vespa.ApplicationID{}, errHint(fmt.Errorf("no application specified: %w", err), "Try the --"+applicationFlag+" flag") } application, err := vespa.ApplicationFromString(app) @@ -139,9 +139,9 @@ func getTargetType() (string, error) { if err != nil { return "", err } - target, err := cfg.Get(targetFlag) - if err != nil { - return "", fmt.Errorf("invalid target: %w", err) + target, ok := cfg.Get(targetFlag) + if !ok { + return "", fmt.Errorf("target is unset") } return target, nil } diff --git a/client/go/cmd/root.go b/client/go/cmd/root.go index 96521737ba9..114d6150284 100644 --- a/client/go/cmd/root.go +++ b/client/go/cmd/root.go @@ -92,11 +92,7 @@ func configureOutput() error { if err != nil { return err } - colorValue, err := config.Get(colorFlag) - if err != nil { - return err - } - + colorValue, _ := config.Get(colorFlag) colorize := false switch colorValue { case "auto": |