-
Couldn't load subscription status.
- Fork 7.3k
Warn when an unknown config key is set #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thank you 🙇
pkg/cmd/config/config.go
Outdated
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type ConfigKey struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I would say that this type need not be exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I will change it (I realised it while coding, but thought we were not exactly following the exported-unexported convention, so did not unexport it 😅 )
| knownKey := false | ||
| for _, configKey := range respectedConfigKeys { | ||
| if key == configKey.name { | ||
| knownKey = true | ||
| break | ||
| } | ||
| } | ||
| if !knownKey { | ||
| iostreams := f.IOStreams | ||
| warningIcon := iostreams.ColorScheme().WarningIcon() | ||
| fmt.Fprintf(iostreams.ErrOut, "%s warning: '%s' is not a known configuration key\n", warningIcon, key) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on moving this code into cfg.Set? We have another PR that is doing config value validation (#2138) and I think it would be nice to have both the key and value validations residing in the same place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually fine with this being here and not within Set() since it's only a warning. Other potential callers of the Set() function should be able to set arbitrary keys without it resulting in a warning printed on stderr.
Although, I do agree with @samcoe that this check is similar to config value validation and could thus live in the config package. Perhaps for now, the logic that searches for a key being among respectedConfigKeys could be moved to the config package and invoked from here like config.IsSupportedConfig(key).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So I think lets wait for #2138 to get merged, then we can decide how we need to go forward with this. I agree that it would be better to keep the validations together, now that we are validating the values also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to update here that I merged in #2138 👍
|
#2138 is merged! You are welcome to bring |
|
@AliabbasMerchant Leave as-is; please! Thank you for your contribution so far 🙏 |
It's better to set this per-host in general, since setting the top-level `git_protocol` key will not have any effect if the per-host setting exists, and it does by default for anyone who ran `auth login`.
Summary
closes #855