]>
Commit | Line | Data |
---|---|---|
add651ee FG |
1 | use clap::{arg, command}; |
2 | ||
3 | fn main() { | |
4 | let matches = command!() // requires `cargo` feature | |
5 | .arg( | |
6 | arg!(<MODE>) | |
7 | .help("What mode to run the program in") | |
8 | .value_parser(["fast", "slow"]), | |
9 | ) | |
10 | .get_matches(); | |
11 | ||
12 | // Note, it's safe to call unwrap() because the arg is required | |
13 | match matches | |
14 | .get_one::<String>("MODE") | |
15 | .expect("'MODE' is required and parsing will fail if its missing") | |
16 | .as_str() | |
17 | { | |
18 | "fast" => { | |
19 | println!("Hare"); | |
20 | } | |
21 | "slow" => { | |
22 | println!("Tortoise"); | |
23 | } | |
24 | _ => unreachable!(), | |
25 | } | |
26 | } |