2022-03-03 18:32:29 +00:00
|
|
|
// Note: this requires the `cargo` feature
|
|
|
|
|
2022-05-23 15:50:11 +00:00
|
|
|
use clap::{arg, command, value_parser, ArgEnum};
|
2021-11-30 18:30:19 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
|
|
|
|
enum Mode {
|
|
|
|
Fast,
|
|
|
|
Slow,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2022-02-15 14:33:38 +00:00
|
|
|
let matches = command!()
|
2021-11-30 18:30:19 +00:00
|
|
|
.arg(
|
|
|
|
arg!(<MODE>)
|
|
|
|
.help("What mode to run the program in")
|
2022-05-23 15:50:11 +00:00
|
|
|
.value_parser(value_parser!(Mode)),
|
2021-11-30 18:30:19 +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::<Mode>("MODE")
|
2021-11-30 18:30:19 +00:00
|
|
|
.expect("'MODE' is required and parsing will fail if its missing")
|
|
|
|
{
|
|
|
|
Mode::Fast => {
|
|
|
|
println!("Hare");
|
|
|
|
}
|
|
|
|
Mode::Slow => {
|
|
|
|
println!("Tortoise");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|