Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AliabbasMerchant
Copy link
Contributor

Summary

closes #855

Copy link
Contributor

@mislav mislav left a 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 🙇

"github.com/spf13/cobra"
)

type ConfigKey struct {
Copy link
Contributor

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

Copy link
Contributor Author

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 😅 )

Comment on lines 100 to 111
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)
}
Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Contributor Author

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

Copy link
Contributor

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 👍

@mislav
Copy link
Contributor

mislav commented Oct 20, 2020

#2138 is merged! You are welcome to bring trunk into this branch if you want to make adjustments for it, but personally I'm not really concerned about the current duplication of where we perform these checks, so if this was merged as-is, we could always refactor down the line when we feel the need.

@AliabbasMerchant
Copy link
Contributor Author

Cool, thanks for the update, @samcoe and @mislav !

@mislav I am fine with anything as such, but I do believe it would be easier if we keep the checks in one common place.

(I guess we can go forward with what @samcoe feels best amongst these two options? Majority wins? 😄 )

@AliabbasMerchant
Copy link
Contributor Author

So what should I do, @mislav @samcoe ?
Should I edit this, or is this going to be directly merged?

@mislav
Copy link
Contributor

mislav commented Oct 26, 2020

@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`.
@mislav mislav merged commit 4a8ab49 into cli:trunk Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent setting incorrect config keys and values

3 participants