-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix: Getting the value of a StringToString pflag #874
Conversation
@sagikazarmark could you take a look at this? |
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.
@terev thanks a lot! I had one comment, but other than that, 👍 !
viper.go
Outdated
@@ -1177,6 +1181,24 @@ func readAsCSV(val string) ([]string, error) { | |||
return csvReader.Read() | |||
} | |||
|
|||
func parseStringToStringFlagValue(val string) map[string]interface{} { |
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.
How about copying the same function from pflag and keeping the implementation as close and possible?
https://github.com/spf13/pflag/blob/master/string_to_string.go#L79
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.
@sagikazarmark i've made this change. i had to tweak the signature and return types slightly to work with GetStringMap that uses cast.ToStringMap
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.
Sure thing, thanks!
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.
Thanks @terev
* add parsing for stringToString flags * add logic to return flags default if not val set, add a test * extract parsing into single func * add a few more cases * return nil if unable to parse instead of panicing * return map[string]interface in order to work with cast.ToStringMap * mostly copy pflags implementation of the conversion to a stringtostring
As viper parses pflag values as strings, string to string values weren't being handled correctly . Fixes #608 .