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

Fix retrieval of pflag stringSlice #240

Merged
merged 1 commit into from
Sep 22, 2016
Merged

Conversation

moorereason
Copy link
Contributor

With some extra trace log formatting changes thrown into the mix.

Fixes #112

With some extra trace log formatting changes thrown into the mix.

Fixes spf13#112
@CLAassistant
Copy link

CLAassistant commented Sep 22, 2016

CLA assistant check
All committers have signed the CLA.

@awfm9
Copy link

awfm9 commented Sep 22, 2016

Don't see any issues with this, thank you for your contribution.

@awfm9 awfm9 merged commit ed0a967 into spf13:master Sep 22, 2016
@aarondl
Copy link

aarondl commented Sep 27, 2016

@awishformore @moorereason

This PR seems to fix #200 (haven't tested)

But note that I changed two hunks in my workaround, one in find() as in this PR (pretty much the same code) and one in Get() . I wonder if the second one in Get() is necessary. Can anyone who knows the code base advise on this? The code I put in that case is probably wrong, but the fact that there's a similar type check going on there makes me suspicious. I just want to make sure we covered all the possibilities.

If it's truly done, then we should probably close #200 as well.

@awfm9
Copy link

awfm9 commented Sep 27, 2016

I'll try to take a look soon.

Copy link

@shenwei356 shenwei356 left a comment

Choose a reason for hiding this comment

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

fix bug of string_slice with square brackets

switch flag.ValueType() {
case "int", "int8", "int16", "int32", "int64":
return cast.ToInt(flag.ValueString())
case "bool":
return cast.ToBool(flag.ValueString())
case "stringSlice":
s := strings.TrimPrefix(flag.ValueString(), "[")

Choose a reason for hiding this comment

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

This wrongly trims the "[" and "]" in the flags.

Fix it by:

s := flag.ValueString()
return s[1:len(s)-1]

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shenwei356, your solution is probably faster, but strings.TrimPrefix only removes a single "[" character. The problem with pflag was that it used strings.Trim which would remove multiples.

Choose a reason for hiding this comment

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

you are right!

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.

5 participants