Skip to main content

#
04_01_enum_derive/
04_01_enum.rs

    1use clap::{Parser, ValueEnum};
    2
    3#[derive(Parser)]
    4#[command(version, about, long_about = None)]
    5struct Cli {
    6    /// What mode to run the program in
    7    #[arg(value_enum)]
    8    mode: Mode,
    9}
    10
    11#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
    12enum Mode {
    13    /// Run swiftly
    14    Fast,
    15    /// Crawl slowly but steadily
    16    ///
    17    /// This paragraph is ignored because there is no long help text for possible values.
    18    Slow,
    19}
    20
    21fn main() {
    22    let cli = Cli::parse();
    23
    24    match cli.mode {
    25        Mode::Fast => {
    26            println!("Hare");
    27        }
    28        Mode::Slow => {
    29            println!("Tortoise");
    30        }
    31    }
    32}