Skip to main content

#
typed_derive/
builtin.rs

    1use clap::Args;
    2use clap::builder::TypedValueParser as _;
    3
    4use crate::foreign_crate;
    5
    6#[derive(Args, Debug)]
    7pub(crate) struct BuiltInParsers {
    8    /// Support for discrete numbers
    9    #[arg(
    10        long,
    11        default_value_t = 22,
    12        value_parser = clap::builder::PossibleValuesParser::new(["22", "80"])
    13            .map(|s| s.parse::<usize>().unwrap()),
    14    )]
    15    port: usize,
    16
    17    /// Support enums from a foreign crate that don't implement `ValueEnum`
    18    #[arg(
    19        long,
    20        default_value_t = foreign_crate::LogLevel::Info,
    21        value_parser = clap::builder::PossibleValuesParser::new(["trace", "debug", "info", "warn", "error"])
    22            .map(|s| s.parse::<foreign_crate::LogLevel>().unwrap()),
    23    )]
    24    log_level: foreign_crate::LogLevel,
    25}