-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Make methods from ArgMatches panic on unknown argument #2000
Conversation
30c8214
to
67e9ba4
Compare
I am not exactly convinced about the breaking change regarding groups here.
That is why we have debug assertions checking all those cases and warning accordingly. Can we try to separate out the breaking change from this PR and see what happens? |
You don't get it. // Notice that we don't explicitly create the group
// It's just conjured from the thin air behind the scenes
app.
.arg(Arg::new("arg").group("try"))
.arg(Arg::new("opt").group("try")) Now guess what happens if you mistype the name of the group, like "fry"? The wrong group is to be made up in background! No errors, just a footgun. If you aren't convinced of the impact, look at the diff, doc comment on top of the I think this kind of "feature" should be cut out no matter what. It doesn't serve any purpose except saving devs from typing extra |
I understand what you are saying but I am still not convinced. We should prioritise ease-of-use. If they make a typo for a group name, it's their problem. |
Ease of use is composed of many components, the most important being:
The feature in question is optimizing for the first bullet point by sacrificing the last one because the error is just about undiscoverable until you actually run and thoroughly test your program. Without it, the first point is only very slightly damaged, if at all, because these Incidentally, this goes against clap's own convention when you apply it to args. Does Ad absurdum: what does rustc do when it encounters an unknown name? Does it create a hidden variable and initialize it with |
67e9ba4
to
30683c6
Compare
30683c6
to
ac41a81
Compare
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.
bors r+
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
ac41a81
to
99b88df
Compare
99b88df
to
0cbec63
Compare
bors r+ |
🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
bors r+ |
Build succeeded: |
Closes #604
This PR also introduces a little breaking change: you now need to explicitly define
ArgGroup
s, you can't justArg::group("group")
and have the group created behind the scenes". I STRONGLY believe that this worth it because it turns out it's really easy to mistype the arg name or confuse it with short/long flag names. Some of our tests are broken because of it, and one of our examples was teaching incorrect behavior. The check introduced makes sure this kind of errors won't happen again.