Skip to content
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

Properly handle string slice values #296

Merged
merged 2 commits into from
Apr 17, 2017
Merged

Properly handle string slice values #296

merged 2 commits into from
Apr 17, 2017

Conversation

orian
Copy link
Contributor

@orian orian commented Jan 4, 2017

Added a code handling a pflag.StringSlice values. Also tested most cases.

It fixes #200.

Similar to: #244

@CLAassistant
Copy link

CLAassistant commented Jan 4, 2017

CLA assistant check
All committers have signed the CLA.

@nullbio
Copy link

nullbio commented Jan 14, 2017

Nice, I was just coming to see if any progress had been made on this yet. Hoping to see this merged soon :-)

@@ -880,7 +881,9 @@ func (v *Viper) find(lcaseKey string) interface{} {
return cast.ToBool(flag.ValueString())
case "stringSlice":
s := strings.TrimPrefix(flag.ValueString(), "[")
return strings.TrimSuffix(s, "]")
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud: maybe the error should not be silently ignored but shouted loudly as panic? Any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We silently swallow errors in the other cases, so ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's be consistent ;)

Copy link
Contributor Author

@orian orian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the change be merged?

@@ -880,7 +881,9 @@ func (v *Viper) find(lcaseKey string) interface{} {
return cast.ToBool(flag.ValueString())
case "stringSlice":
s := strings.TrimPrefix(flag.ValueString(), "[")
return strings.TrimSuffix(s, "]")
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's be consistent ;)

@orian
Copy link
Contributor Author

orian commented Jan 23, 2017

@bep what about the merge? ;-)

@Willyham
Copy link

Would love to see this be merged soon.

@theckman
Copy link

theckman commented Apr 17, 2017

@bep Hey there, just wanted to ping you again to see if you'd be interested in merging this! I'm hitting this issue in a new piece of software I'm writing, and would like to use viper to handle the []string PFlag properly.

@bep bep merged commit 0967fc9 into spf13:master Apr 17, 2017
huguesalary added a commit to betabrand/minikube that referenced this pull request Aug 7, 2017
The previous vendored `github.com/spf13/viper` had this bug spf13/viper#296 .

This commit upgrades to the latest `github.com/spf13/viper` and closes kubernetes#1797.
r2d4 pushed a commit to r2d4/minikube that referenced this pull request Aug 21, 2017
The previous vendored `github.com/spf13/viper` had this bug spf13/viper#296 .

This commit upgrades to the latest `github.com/spf13/viper` and closes kubernetes#1797.
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.

String Slices from pflags are not handled correctly by viper.
6 participants