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

Update pflag to avoid flag parsing gotchas #1183

Merged
merged 1 commit into from Jul 4, 2018
Merged

Conversation

@squaremo
Copy link
Member

squaremo commented Jun 29, 2018

github.com/spf13/pflag has moderately wacky error handling, which it
probably inherited from flag in stdlib.

You can either choose to let it handle flag parsing errors for you, by
printing the error and usage then exiting (ExitOnError); or, return
them to you so you can decide what to do (ContinueOnError).

The revision of pflag we were using (in the first mode) was silent in
the case that parsing a flag value failed -- so we changed to use
the second mode, and handled errors by printing the usage
ourselves. However, it wasn't silent in other cases, meaning we would
output the usage twice (including if you used the --help flag).

The newer revision of pflag 1. doesn't output usage if you've told it
you'll handle errors, and 2. doesn't remain silent when it fails to
parse a value. So it would work for us in either mode; since we're
already using ContinueOnError, just tidy that up.

Fixes #1176.

github.com/spf13/pflag has moderately wacky error handling, which it
probably inherited from `flag` in stdlib.

You can either choose to let it handle flag parsing errors for you, by
printing the error and usage then exiting (`ExitOnError`); or, return
them to you so you can decide what to do (`ContinueOnError`).

The revision of pflag we were using (in the first mode) was silent in
the case that parsing a flag _value_ failed -- so we changed to use
the second mode, and handled errors by printing the usage
ourselves. However, it wasn't silent in other cases, meaning we would
output the usage twice (including if you used the `--help` flag).

The newer revision of pflag 1. doesn't output usage if you've told it
you'll handle errors, and 2. doesn't remain silent when it fails to
parse a value. So it would work for us in either mode; since we're
already using ContinueOnError, just tidy that up.
@squaremo squaremo requested a review from aaron7 Jul 3, 2018
@aaron7
aaron7 approved these changes Jul 4, 2018
@squaremo squaremo merged commit dfa97ba into master Jul 4, 2018
1 check passed
1 check passed
ci/circleci: build Your tests passed on CircleCI!
Details
@squaremo squaremo deleted the issue/1176-deal-with-help branch Jul 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.