Created
June 5, 2016 23:46
-
-
Save cite-reader/1286a870b67fb94cd29e44f007cc6908 to your computer and use it in GitHub Desktop.
Testing a Clap arg with default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate clap; | |
use clap::{Arg, App}; | |
fn main() { | |
let matches = App::new("A test") | |
.arg(Arg::with_name("has-default") | |
.short("d") | |
.takes_value(true)) | |
.get_matches(); | |
let value: u32 = matches.value_of("has-default").and_then(|s| s.parse().ok()).unwrap_or(42); | |
println!("The flag's value was {}", value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment