2022-02-15 14:33:38 +00:00
|
|
|
use clap::{arg, command};
|
2015-03-29 01:19:51 +00:00
|
|
|
|
|
|
|
fn main() {
|
2022-07-19 18:29:31 +00:00
|
|
|
let matches = command!() // requires `cargo` feature
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2021-11-30 18:30:19 +00:00
|
|
|
arg!(<MODE>)
|
2021-11-18 16:17:15 +00:00
|
|
|
.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();
|
2015-03-29 01:19:51 +00:00
|
|
|
|
|
|
|
// Note, it's safe to call unwrap() because the arg is required
|
2021-11-12 14:42:25 +00:00
|
|
|
match matches
|
2022-05-23 15:50:11 +00:00
|
|
|
.get_one::<String>("MODE")
|
2021-11-12 14:42:25 +00:00
|
|
|
.expect("'MODE' is required and parsing will fail if its missing")
|
2022-05-23 15:50:11 +00:00
|
|
|
.as_str()
|
2021-11-12 14:42:25 +00:00
|
|
|
{
|
2015-03-29 01:19:51 +00:00
|
|
|
"fast" => {
|
2021-11-12 01:06:50 +00:00
|
|
|
println!("Hare");
|
2018-01-25 04:05:05 +00:00
|
|
|
}
|
2015-03-29 01:19:51 +00:00
|
|
|
"slow" => {
|
2021-11-12 01:06:50 +00:00
|
|
|
println!("Tortoise");
|
2018-01-25 04:05:05 +00:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
2015-03-29 01:19:51 +00:00
|
|
|
}
|
2016-01-27 22:22:34 +00:00
|
|
|
}
|