clap/examples/tutorial_derive/04_01_enum.rs

33 lines
646 B
Rust
Raw Normal View History

use clap::{Parser, ValueEnum};
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
/// What mode to run the program in
#[arg(value_enum)]
mode: Mode,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum Mode {
2022-10-04 12:32:49 +00:00
/// Run swiftly
Fast,
2022-10-04 12:32:49 +00:00
/// Crawl slowly but steadily
///
/// This paragraph is ignored because there is no long help text for possible values.
Slow,
}
fn main() {
let cli = Cli::parse();
match cli.mode {
Mode::Fast => {
println!("Hare");
}
Mode::Slow => {
println!("Tortoise");
}
}
}