// 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 sort according to -h, --head unsort the first lines. -t, --tail unsort the last lines. Other options: --color use markers to highlight the matching strings -e, --exp regular expression. sort by the entires match -u, --unique output only the first line of an equal --max-buffer max buffer size -H, --help display this help and exit -V, --version display version information and exit "; #[repr(u8)] #[derive(Debug, PartialEq, Eq)] enum CmdOp { Reverse, AccordingTo, Head, Tail, Color, Exp, Unique, MaxBuffer, Help, Version, } impl std::convert::From 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;10] = [ Opt { sho: 0u8, lon: "according-to", has: Arg::Yes, num: CmdOp::AccordingTo.to(), }, Opt { sho: 0u8, lon: "color", has: Arg::Yes, num: CmdOp::Color.to(), }, Opt { sho: b'e', lon: "exp", has: Arg::Yes, num: CmdOp::Exp.to(), }, 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: 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't', lon: "tail", has: Arg::Yes, num: CmdOp::Tail.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);7] = [ (b'H',4),(b'V',9),(b'e',2),(b'h',3),(b'r',6),(b't',7),(b'u',8),]; #[derive(Debug, Default, PartialEq, Eq)] pub struct CmdOptConf { pub prog_name: String, // pub flg_reverse: bool, pub opt_according_to: OptAccordingToWord, pub opt_head: Option, pub opt_tail: Option, pub opt_color: OptColorWhen, 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, } 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 { match nv.val { Some(x) => Ok(x.to_string()), None => Err(OptParseError::missing_option_argument(&nv.opt.lon_or_sho())), } } fn value_to_usize(nv: &NameVal<'_>) -> Result { match nv.val { Some(x) => match x.parse::() { 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())), } } fn value_to_opt_according_to_word(nv: &NameVal<'_>) -> Result { match nv.val { Some(s) => match FromStr::from_str(s) { Ok(x) => Ok(x), 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())), } } fn value_to_opt_color_when(nv: &NameVal<'_>) -> Result { match nv.val { Some(s) => match FromStr::from_str(s) { Ok(x) => Ok(x), 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())), } } fn value_to_opt_max_buffer_size(nv: &NameVal<'_>) -> Result { match nv.val { Some(s) => match FromStr::from_str(s) { Ok(x) => Ok(x), 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())), } }