reject flags claimed by more than one option - #189
Closed
metsw24-max wants to merge 1 commit into
Closed
Conversation
Owner
|
This is a duplicate of #187, I'll check out both, but only one will be able to be merged. |
Owner
|
The implementation here is simple and correct, but I'd like evidence that it works across groups under the same parser (but not subcommands, as those separate their arguments). |
Owner
|
After poking at it a bit, I'm closing this in favor of the earlier one, as I've already interfaced with that one and it's been changed to handle what I wanted it to handle (which is to check on every added flag, rather than on parse). Thanks for the PR; sorry this one didn't make it in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Duplicate flag matchers are accepted silently
Two options that register the same short or long flag currently parse without complaint (issue #117):
Match()returns the first option in tree order, so the second can never be reached and any value meant for it is quietly dropped.ArgumentParser::ParseandSubparser::Parsenow walk the reachable flags withGetAllFlags()and raise aUsageError(or setError::UsageunderARGS_NOEXCEPT) naming the offending flag when one is claimed by more than one option. Going throughGetAllFlags()keeps the check aware of command boundaries, so sibling subcommands may still reuse a name and a single option shared between groups does not report itself.Regression tests cover both parsing modes and the subcommand case; they fail on master and pass with the change.