-
Notifications
You must be signed in to change notification settings - Fork 365
Add PassUnknownFlagsToArgs to allow get unknown flags via Args()
#338
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
base: master
Are you sure you want to change the base?
Conversation
|
@spf13 👋 Any chance of this landing? I have exactly this use-case as well :) If it needs work, I would be happy to take it on |
tomasaschan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think this looks OK, but there's a conflict after merging #295 that needs to be resolved by rebasing.
Co-authored-by: Tomas Aschan <[email protected]>
Co-authored-by: Tomas Aschan <[email protected]>
aee6b4c to
1190bb9
Compare
|
@tomasaschan Thanks for reviewing! I introduced your code suggestion, rebased onto origin/main and resolved conflicts. Tests pass and all |
| case f.ParseErrorsAllowlist.UnknownFlags: | ||
| if f.ParseErrorsAllowlist.PassUnknownFlagsToArgs { | ||
| return a, &unknownFlagError{ | ||
| UnknownFlags: s, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't spot this before, but putting this branch here instead of in its own case means users will have to specify both this option and UnknownFlags: true for this to have any effect. Is that intentional?
Either way, it seems to me like this PR introduces a new mode to handle unknown flags where there are already two. Before this change, depending on the value of UnknownFlags an unknown flag would either cause an error or be ignored (but consumed). Now, it can also be ignored but not consumed (and instead passed to Args), but controlling this with two boolean feature flags results in an API where there's a combination of values that doesn't make sense.
Maybe it would be better to change UnknownFlags to an enum with constants for ErrorOnUnknown, IgnoreUnknown and PassUnknownToArgs instead? I realize this means the change is breaking, but we have a bunch of ideas lined up that would require breaking changes, so I think it's time to start thinking about what the path to 2.0 looks like anyway. Would you be open to this idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
I believe switching to enum can be achieved preserving backward compatibility. Created #440 . But that requires complicated codes for backward compatibility, and it's OK to wait for 2.0.
Close #337
FlagSet.ParseErrorsWhitelist.UnknownFlags=truebehaves like this:--unknown-flagare unknownThis request adds
FlagSet.ParseErrorsWhitelist.PassUnknownFlagsToArgs, and setting it totrueresults following behavior:Args()withFlagSet.ParseErrorsWhitelist.PassUnknownFlagsToArgs=true:Any unknown and unprocessed flags are passed to
Args().