clap/examples/11_only_specific_values.rs

29 lines
708 B
Rust
Raw Normal View History

use clap::{App, Arg};
fn main() {
2018-01-25 04:05:05 +00:00
let matches = App::new("myapp")
.about("does awesome things")
.arg(
Arg::new("MODE")
.help("What mode to run the program in")
2018-01-25 04:05:05 +00:00
.index(1)
.possible_values(["fast", "slow"])
2018-01-25 04:05:05 +00:00
.required(true),
)
.get_matches();
// Note, it's safe to call unwrap() because the arg is required
match matches
.value_of("MODE")
.expect("'MODE' is required and parsing will fail if its missing")
{
"fast" => {
println!("Hare");
2018-01-25 04:05:05 +00:00
}
"slow" => {
println!("Tortoise");
2018-01-25 04:05:05 +00:00
}
_ => unreachable!(),
}
}