Search code examples
rustcommand-line-argumentsclap

How to specify a default value for an argument for clap_app! macro?


I want to use clap_app! macro to define an argument which should have a default value. Unfortunately, there is nothing in the docs, and my naive attempt didn't work:

#[macro_use]
extern crate clap;

fn main() {
    let matches = clap_app!(myapp =>
        (@arg seconds: -u +takes_value +default_value("1.0") "Update time")
    ).get_matches();
    println!("{}", matches.value_of("seconds").unwrap())
}

How can I specify a default value for an argument within clap_app! macro?


Solution

  • This is currently impossible with number, https://github.com/kbknapp/clap-rs/issues/1035.

    But it's should be:

    (@arg seconds: -u +takes_value default_value[1.0] "Update time")