clap/examples/tutorial_builder/04_01_possible.rs

29 lines
673 B
Rust
Raw Normal View History

// Note: this requires the `cargo` feature
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")
2022-05-23 15:50:11 +00:00
.value_parser(["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
2022-05-23 15:50:11 +00:00
.get_one::<String>("MODE")
.expect("'MODE' is required and parsing will fail if its missing")
2022-05-23 15:50:11 +00:00
.as_str()
{
"fast" => {
println!("Hare");
2018-01-25 04:05:05 +00:00
}
"slow" => {
println!("Tortoise");
2018-01-25 04:05:05 +00:00
}
_ => unreachable!(),
}
}