Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Update pflag to avoid flag parsing gotchas #1183

Merged
merged 1 commit into from
Jul 4, 2018

Conversation

squaremo
Copy link
Member

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 July 3, 2018 07:52
@squaremo squaremo merged commit dfa97ba into master Jul 4, 2018
@squaremo squaremo deleted the issue/1176-deal-with-help branch July 4, 2018 14:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants