// WARN: This file is auto generated by flood-tide-gen
const OPTIONS_TEXT: &str = r"Ordering options:
  -r, --reverse                 reverse the result of comparisons
      --according-to <word>     sort according to WORD: string, numeric, month, version

Other options:
  -e, --exp <exp>               regular expression. sort via this match point.
  -u, --unique                  output only the first line of an equal.
      --max-buffer <size>       max buffer size. if reading size is more than <size>, then it not output, quit and display error message.

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

#[repr(u8)]
#[derive(Debug, PartialEq)]
enum CmdOp {
    Reverse,
    AccordingTo,
    Exp,
    Unique,
    MaxBuffer,
    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;7] = [
    Opt { sho: 0u8,  lon: "according-to",  has: Arg::Yes, num: CmdOp::AccordingTo.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: 0u8,  lon: "max-buffer",    has: Arg::Yes, num: CmdOp::MaxBuffer.to(), },
    Opt { sho: b'r', lon: "reverse",       has: Arg::No,  num: CmdOp::Reverse.to(), },
    Opt { sho: b'u', lon: "unique",        has: Arg::No,  num: CmdOp::Unique.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',2),(b'V',6),(b'e',1),(b'r',4),(b'u',5),];

#[derive(Debug, Default, PartialEq)]
pub struct CmdOptConf {
    pub prog_name: String,
    //
    pub flg_reverse: bool,
    pub opt_according_to: OptAccordingToWord,
    pub opt_exp: String,
    pub flg_unique: bool,
    pub opt_max_buffer: OptMaxBufferSize,
    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_string(nv: &NameVal<'_>) -> Result<String, OptParseError> {
    match nv.val {
        Some(x) => Ok(x.to_string()),
        None => Err(OptParseError::missing_option_argument(&nv.opt.lon)),
    }
}
