clap/examples/tutorial_builder/04_01_possible.rs

26 lines
619 B
Rust
Raw Normal View History

use clap::{app_from_crate, arg};
fn main() {
let matches = app_from_crate!()
2018-01-25 04:05:05 +00:00
.arg(
arg!(<MODE>)
.help("What mode to run the program in")
.possible_values(["fast", "slow"]),
2018-01-25 04:05:05 +00:00
)
.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!(),
}
}