// WARN: This file is auto generated by flood-tide-gen
const OPTIONS_TEXT: &str = r"Options:
  -e, --exp <exp>   write it in the cyclic color (default: ' ([0-9A-Z]{3,}):')

  -H, --help        display this help and exit
  -V, --version     display version information and exit
  -X <x-options>    x options. try -X help
";

#[repr(u8)]
#[derive(Debug, PartialEq, Eq)]
enum CmdOp {
    Exp,
    Help,
    Version,
    UcX,
}

impl CmdOp {
    pub const fn to(self) -> OptNum {
        self as OptNum
    }
}

impl std::convert::From<u8> for CmdOp {
    fn from(value: u8) -> Self {
        match value {
            0 => CmdOp::Exp,
            1 => CmdOp::Help,
            2 => CmdOp::Version,
            3 => CmdOp::UcX,
            _ => unreachable!(),
        }
    }
}

#[rustfmt::skip]
const OPT_ARY: [Opt;4] = [
    Opt { sho: b'X', lon: "",              has: Arg::Yes, num: CmdOp::UcX.to(), },
    Opt { sho: b'e', lon: "exp",           has: Arg::Yes, num: CmdOp::Exp.to(), },
    Opt { sho: b'H', lon: "help",          has: Arg::No,  num: CmdOp::Help.to(), },
    Opt { sho: b'V', lon: "version",       has: Arg::No,  num: CmdOp::Version.to(), },
];

#[rustfmt::skip]
const OPT_ARY_SHO_IDX: [(u8,usize);4] = [
(b'H',2),(b'V',3),(b'X',0),(b'e',1),];

#[derive(Debug, Default, PartialEq, Eq)]
pub struct CmdOptConf {
    pub prog_name: String,
    //
    pub opt_exp: String,
    pub flg_help: bool,
    pub flg_version: bool,
    pub opt_uc_x: Vec<OptUcXParam>,
    //
    pub arg_params: Vec<String>,
}

impl flood_tide::HelpVersion for CmdOptConf {
    fn is_help(&self) -> bool {
        self.flg_help
    }
    fn is_version(&self) -> bool {
        self.flg_version
    }
}

fn value_to_type<T>(nv: &NameVal<'_>) -> Result<T, OptParseError>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Display,
{
    match nv.val {
        Some(x) => match x.parse::<T>() {
            Ok(d) => Ok(d),
            Err(err) => Err(OptParseError::invalid_option_argument(
                &nv.opt.lon_or_sho(),
                &err.to_string(),
            )),
        },
        None => Err(OptParseError::missing_option_argument(&nv.opt.lon_or_sho())),
    }
}
