// WARN: This file is auto generated by flood-tide-gen
const OPTIONS_TEXT: &str = r"Options:
  -a, --append <file>   append to the <file>, do not overwrite [unimplemented]
  -p, --pipe-out <num>  write to pipe <num> [unimplemented]

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

#[repr(u8)]
#[derive(Debug, PartialEq)]
enum CmdOp {
    Append,
    PipeOut,
    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;4] = [
    Opt { sho: b'a', lon: "append",        has: Arg::Yes, num: CmdOp::Append.to(), },
    Opt { sho: b'H', lon: "help",          has: Arg::No,  num: CmdOp::Help.to(), },
    Opt { sho: b'p', lon: "pipe-out",      has: Arg::Yes, num: CmdOp::PipeOut.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',1),(b'V',3),(b'a',0),(b'p',2),];

#[derive(Debug, Default, PartialEq)]
pub struct CmdOptConf {
    pub prog_name: String,
    //
    pub opt_append: String,
    pub opt_pipe_out: String,
    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)),
    }
}
