clap/examples/tutorial_builder/04_01_possible.rs

26 lines
605 B
Rust
Raw Normal View History

2022-02-15 14:33:38 +00:00
use clap::{arg, command};
fn main() {
2022-02-15 14:33:38 +00:00
let matches = command!()
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!(),
}
}