clap
clap copied to clipboard
`ArgAction::Count` starts from `0` rather than `default_value`
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
Clap Version
4.5.0
Minimal reproducible code
use clap::{ArgAction, Parser};
#[derive(Debug, Clone, Parser)]
pub struct CliArgs {
#[clap(short = 'v', action = ArgAction::Count, default_value_t=5)]
pub verbose: u8,
}
fn main() {
let args = CliArgs::parse();
println!("verbose count: {}", args.verbose);
}
Steps to reproduce the bug with the above code
$ cargo run -- -vvv
Actual Behaviour
default_value_t
is not taken into consideration for the starting point of Count
output:
$ cargo run
verbose count: 5
$ cargo run -- -vvv
verbose count: 3
Expected Behaviour
default_value_t
is taken into consideration for the starting point of Count
output:
$ cargo run
verbose count: 5
$ cargo run -- -vvv
verbose count: 8
Additional Context
Debug Output
No response