How do I specify a boolean command line flag using Clap?

The currently accepted answer is slightly outdated, you no longer have to specify required(false) when you specify takes_value(false). So, what you need is:

.arg(
    Arg::with_name("metal")
        .long("metal-micky")
        .takes_value(false)
        .help("I want metal mickey")

and check the presence with matches.is_present("metal").


Don't know if this is the "approved" method but I use Args::takes_value:

.arg(
    Arg::with_name("metal")
        .long("metal-micky")
        .required(false)
        .takes_value(false)
        .help("I want metal micky"),
)

Then check if the flag was passed with matches.is_present("metal")

Tags:

Rust

Clap