fix(parser): AllowHyphenValues correctly handles long args in first pos #4039
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.
pretty much just @epage's #3389, but with a bunch of unit tests
fixes #3880
fixes #1538
fixes #3887 (specifically the "... none of them seem to allow for the first argument to have two hyphens ..." part)
rephrasing this fix to specifically focus on
allow_hyphen_values(true)
as it's the root cause of the bug in #1538This specifically only changes the parsing behavior when
allow_hyphen_values(true)
is used. Iow, the parsing behavior of setting saytrailing_var_args(true)
without settingallow_hyphen_values(true)
does not change.A note on whether this is a "bug fix", the documentation for
Arg::allow_hyphen_values
assumes thatprog --arg -- -- val
works (it doesn't without this PR), so I personally feel this can be reasonably treated as a bug fix and not an explicit change in behavior to users?Behaviors that change with this PR
allow_hyphen_values(true)
on aCommand
that has optional long flags: mistyped/unrecognized optional long flags will always be treated as argument values and will not surface unrecognized flag errorstrailing_var_args(true)
on aCommand
that hasallow_hyphen_values(true)
set on the finalArg
: mistyped/unrecognized long flag will result in that flag, plus all subsequent args, being treated as values