-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Clap panics on positional bools in debug builds #4467
Comments
That said, we can look into detecting if its positional (no shorts or longs) and skip that. I have some hesitance around this as we might not have all of the information we need in all of the right places. I also think we should have a debug_assert about a positional argument taking 0 values to help catch this earlier. |
Wondered if we had this for clap-rs#4467. Figured we should actually test it.
It looks like we do have an existing assert for this. For me, in debug builds, I get a panic. We generally recommend having a test that does use clap::CommandFactory;
Test::command().debug_assert() to help catch these |
Yes, this is mentioned in the bug report above. I used your
|
Not sure I understand. I do want that describe behaviour, don't I? However it is not what actually seems to happen, when I execute the command as described without supplying a
I do think this assert is rather useless since we're talking about a command line parsing library here and the only people who'd even have a remote chance of catching this are the developers who're doing the |
Are you wanting a flag or a positional value? For a flag, you also need to opt-in to For a positional, you need to override the default
|
I don't really care, I was hoping for a positional (the documentation in https://docs.rs/clap/latest/clap/_derive/index.html#arg-types does call the effect a flag though -- might want to straighten out terminology a bit) but the synopsis indicated that this was somehow optional. Then I played around with specifying it as flag, suddently changing the synopsis to something completely different. I don't really understand why the default action is a non-working
|
All of what you saw comes back to the general assumption that |
I think at least the documentation could be clarified to point out that pitfall and maybe provide an example for positional bool. |
It should not be the case, this generated broken parser
And you do not generate compile error, even though this parser never going to work |
#3864 is a similar case where we could move the error to be at compile time. #3133 represents the case where this is a lot more difficult. Downsides to moving things to compile errors
|
Then do not force flag behavior for boolean, it is simple as that. You do not slow compile times. Please see example solution |
That is not what people will generally want with |
It depends on your use case. Rejecting good UX just because you want to force your opinion about boolean on others is not good |
Please complete the following tasks
Rust Version
rustc 1.64.0 (a55dd71d5 2022-09-19)
Clap Version
4.0.22
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
Expected Behaviour
send_resp
shouldn't be rendered as an optional argument in the synopsis and if supplied should result in the parsed variable to be false.Additional Context
As a bonus bug:
If run like this, the synopsis changes:
And in dev mode it panics:
Debug Output
No response
The text was updated successfully, but these errors were encountered: