-
-
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
ArgMathces::args_present
behaviour with ArgAction::SetTrue
#5860
Comments
The documentation says "present on command line" but the behavior is if any ids are present, like With The The question is whether we should change the docs or the behavior. |
Well, personally, I think it's very important to be able to check whether some args were provided via command line or not. If we change the docs, the behavior of I'm not very familiar with clap yet, so I'm sorry if I'm saying nonsense things |
In #3382, we added In clap 3, flag's only set a value when passed in. With #3786, the new In #3814, we renamed We also have the |
I see, thank you for the explanation. But I still deeply convinced that checking if "any arg presented on the command line" is important feature (at least for my purposes). |
Note that wasn't necessarily a comment about what should be done for this issue but notes I took as I researched how we got here and how the term "present" is used. This is important background for understanding where to go from here. For instance
|
I think for my initial purpose to check whether any argument was provided on the command line or not the next code can be used: // no args provided
if std::env::args() == 1 {
// do some stuff ...
} But the current doc of
And I find it confusing, because it's not true it we use So my suggestion is just change its documentation. For checking presence of arguments on the command line the above simple code can be used |
That works for the root command but not any subcommands. If we changed the documentation, we'd need to also deprecate and make a new name available because |
Doing a quick browse on github
|
When we switched flags to `ArgAction::SetTrue`, we overlooked updating `args_present`. Because of the default value for `ArgAction::SetTrue`, `args_present` will always report true when a flag is defined. Looking over uses on github, this will fix a couple bugs but should otherwise be unnoticeable. Fixes clap-rs#5860
When we switched flags to `ArgAction::SetTrue`, we overlooked updating `args_present`. Because of the default value for `ArgAction::SetTrue`, `args_present` will always report true when a flag is defined. I went with the trivial implementation for now. We could proactively track this but was unsure about correctness vs overhead and so I thought I'd have those using it pay for it. Looking over uses on github, this will fix a couple bugs but should otherwise be unnoticeable. Fixes clap-rs#5860
When we switched flags to `ArgAction::SetTrue`, we overlooked updating `args_present`. Because of the default value for `ArgAction::SetTrue`, `args_present` will always report true when a flag is defined. I went with the trivial implementation for now. We could proactively track this but was unsure about correctness vs overhead and so I thought I'd have those using it pay for it. Looking over uses on github, this will fix a couple bugs but should otherwise be unnoticeable. Fixes clap-rs#5860
Please complete the following tasks
Rust Version
rustc 1.85.0-nightly
Clap Version
4.5.23
Minimal reproducible code
This code panic with message
No args were provided, but
args_present()
returns true, which I think counterintuitiveSteps to reproduce the bug with the above code
cargo run
Actual Behaviour
matches.args_present()
returns trueExpected Behaviour
matches.args_present()
returns false if no arguments were provided despiteArg::new("show").action(ArgAction::SetTrue)
Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered: