clap icon indicating copy to clipboard operation
clap copied to clipboard

[derive] Argument `test`'s selected action SetTrue contradicts `takes_value`

Open hasezoey opened this issue 5 months ago • 5 comments

Please complete the following tasks

Rust Version

rustc 1.76.0 (07dca489a 2024-02-04)

Clap Version

4.5.3

Minimal reproducible code

use clap::Parser;

#[derive(Parser, Debug)]
#[clap(name = "testing")]
pub struct TestArg {
    #[arg(
        long = "test",
        default_missing_value = "true",
        num_args = 0..=1,
        require_equals = true,
    )]
    pub test: bool,
}

fn main() {
    let args = cli::TestArg::parse();

    println!("{:#?}", args);
}

Steps to reproduce the bug with the above code

cargo run -- --test=false

Actual Behaviour

Panic:

thread 'main' panicked at /home/hasezoey/.local/cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.2/src/builder/debug_asserts.rs:708:9:
Argument `test`'s selected action SetTrue contradicts `takes_value

Expected Behaviour

No panic, as per documentation default_missing_value.

Additional Context

i know that default_missing_value is currently not documented in derive attributes, but i thought it would work anyway.

in case it is not clear, i am trying to do the following without problems:

cargo run --  # test = false
cargo run --  --test # test = true
cargo run --  --test=true # test = true
cargo run --  --test=false # test = false

Debug Output

[clap_builder::builder::command]Command::_do_parse
[clap_builder::builder::command]Command::_build: name="testing"
[clap_builder::builder::command]Command::_propagate:testing
[clap_builder::builder::command]Command::_check_help_and_version:testing expand_help_tree=false
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_propagate_global_args:testing
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:test
thread 'main' panicked at /home/hasezoey/.local/cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.2/src/builder/debug_asserts.rs:708:9:
Argument `test`'s selected action SetTrue contradicts `takes_value`

hasezoey avatar Mar 24 '24 16:03 hasezoey