Skip to content

Properly handle string slice values#296

Merged
bep merged 2 commits intospf13:masterfrom
orian:iss200
Apr 17, 2017
Merged

Properly handle string slice values#296
bep merged 2 commits intospf13:masterfrom
orian:iss200

Conversation

@orian
Copy link
Copy Markdown
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
Copy Markdown

CLAassistant commented Jan 4, 2017

CLA assistant check
All committers have signed the CLA.

@nullbio
Copy link
Copy Markdown

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

s := strings.TrimPrefix(flag.ValueString(), "[")
return strings.TrimSuffix(s, "]")
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

s := strings.TrimPrefix(flag.ValueString(), "[")
return strings.TrimSuffix(s, "]")
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

orian commented Jan 23, 2017

@bep what about the merge? ;-)

@Willyham
Copy link
Copy Markdown

Would love to see this be merged soon.

@theckman
Copy link
Copy Markdown

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