-
-
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
ArgAction::Count
starts from 0
rather than default_value
#5483
Comments
ArgAction::Count
doesn't recognize default_value_t
I am seeing the same behavior for both Could you give more details, like copies of the output that is expected and unexpected? #!/usr/bin/env nargo
---
[dependencies]
clap = { path = "../clap", features = ["derive"] }
---
use clap::{ArgAction, Parser};
#[derive(Debug, Clone, Parser)]
pub struct CliArgs {
#[arg(short = 'v', action = ArgAction::Count, default_value_t=5)]
pub verbose: u8,
}
fn main() {
let args = CliArgs::parse();
println!("verbose count: {}", args.verbose);
} $ ./clap-5483.rs
verbose count: 5
$ ./clap-5483.rs -vvv
verbose count: 3 Running #!/usr/bin/env nargo
---
[dependencies]
clap = { path = "../clap", features = ["derive"] }
---
use clap::{ArgAction, Parser};
#[derive(Debug, Clone, Parser)]
pub struct CliArgs {
#[arg(short = 'v', action = ArgAction::Count, default_value="5")]
pub verbose: u8,
}
fn main() {
let args = CliArgs::parse();
println!("verbose count: {}", args.verbose);
} $ ./clap-5483.rs
verbose count: 5
$ ./clap-5483.rs -vvv
verbose count: 3 |
@epage Thank you for your reply. I updated my comment above. TL;DR I expect, that |
In all ways within clap, This means that your application needs to take this into account. https://github.com/clap-rs/clap-verbosity-flag is a crate that encodes all of this for that one specific use case. I'm hesitant to change it and inclined to close this but I have just enough doubt that I think I'll leave this open to see what additional insights it might generate. |
ArgAction::Count
doesn't recognize default_value_t
ArgAction::Count
starts from 0
rather than default_value
I've updated the Issue to reflect the latest clarification. To be clear, there is no difference in behavior between |
It could be a different action if there's no way to change this one. At least clarification for this action is required. Example could be found in my recently published tool I'd like to start my verbose level with 2 (Info). |
Added a clarification in 11ff6cc There is a cost for everything we add to the API. I'd be hesitant to add a variant that changes the default behavior especially when this can be worked around. I'd be more inclined towards the custom Actions that I've been considering. |
Please complete the following tasks
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
Clap Version
4.5.0
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
default_value_t
is not taken into consideration for the starting point ofCount
output:
Expected Behaviour
default_value_t
is taken into consideration for the starting point ofCount
output:
Additional Context
Debug Output
No response
The text was updated successfully, but these errors were encountered: