// WARN: This file is auto generated by flood-tide-gen
const OPTIONS_TEXT: &str = r"Options:
  -h, --head <num>      output the first <num> lines.
  -t, --tail <num>      output the last <num> lines.
  -i, --inverse         output the body, except for head and tail.

  -H, --help        display this help and exit
  -V, --version     display version information and exit
";

#[repr(u8)]
#[derive(Debug, PartialEq)]
enum CmdOp {
    Head,
    Tail,
    Inverse,
    Help,
    Version,
}

impl std::convert::From<u8> for CmdOp {
    fn from(value: u8) -> Self {
        unsafe { std::mem::transmute(value) }
    }
}
impl CmdOp {
    pub const fn to(self) -> OptNum {
        self as OptNum
    }
}

#[rustfmt::skip]
const OPT_ARY: [Opt;5] = [
    Opt { sho: b'h', lon: "head",          has: Arg::Yes, num: CmdOp::Head.to(), },
    Opt { sho: b'H', lon: "help",          has: Arg::No,  num: CmdOp::Help.to(), },
    Opt { sho: b'i', lon: "inverse",       has: Arg::No,  num: CmdOp::Inverse.to(), },
    Opt { sho: b't', lon: "tail",          has: Arg::Yes, num: CmdOp::Tail.to(), },
    Opt { sho: b'V', lon: "version",       has: Arg::No,  num: CmdOp::Version.to(), },
];

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

#[derive(Debug, Default, PartialEq)]
pub struct CmdOptConf {
    pub prog_name: String,
    //
    pub opt_head: Option<usize>,
    pub opt_tail: Option<usize>,
    pub flg_inverse: bool,
    pub flg_help: bool,
    pub flg_version: bool,
    //
    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_usize(nv: &NameVal<'_>) -> Result<usize, OptParseError> {
    match nv.val {
        Some(x) => match x.parse::<usize>() {
            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())),
    }
}
