clap icon indicating copy to clipboard operation
clap copied to clipboard

`ArgAction::Count` starts from `0` rather than `default_value`

Open eirnym opened this issue 3 months ago • 6 comments

Please complete the following tasks

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

eirnym avatar May 03 '24 12:05 eirnym