// WARN: This file is auto generated by flood-tide-gen
const OPTIONS_TEXT: &str = r"Options:
-a, --all output the all statistics of text, exclude ascii map
-b, --bytes output the byte counts
-c, --chars output the unicode character counts
-l, --lines output the line counts
--map-ascii output the ascii map statistics
-m, --max-line-bytes output the maximum byte counts of line
-w, --words output the word counts
--locale <loc> locale of number format: en, fr, ... posix
-?, --query <q> display available names of locale and exit
-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 {
All,
Bytes,
Chars,
Lines,
MapAscii,
MaxLineBytes,
Words,
Locale,
Query,
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::All,
1 => CmdOp::Bytes,
2 => CmdOp::Chars,
3 => CmdOp::Lines,
4 => CmdOp::MapAscii,
5 => CmdOp::MaxLineBytes,
6 => CmdOp::Words,
7 => CmdOp::Locale,
8 => CmdOp::Query,
9 => CmdOp::Help,
10 => CmdOp::Version,
11 => CmdOp::UcX,
_ => unreachable!(),
}
}
}
#[rustfmt::skip]
const OPT_ARY: [Opt;12] = [
Opt { sho: b'X', lon: "", has: Arg::Yes, num: CmdOp::UcX.to(), },
Opt { sho: b'a', lon: "all", has: Arg::No, num: CmdOp::All.to(), },
Opt { sho: b'b', lon: "bytes", has: Arg::No, num: CmdOp::Bytes.to(), },
Opt { sho: b'c', lon: "chars", has: Arg::No, num: CmdOp::Chars.to(), },
Opt { sho: b'H', lon: "help", has: Arg::No, num: CmdOp::Help.to(), },
Opt { sho: b'l', lon: "lines", has: Arg::No, num: CmdOp::Lines.to(), },
Opt { sho: 0u8, lon: "locale", has: Arg::Yes, num: CmdOp::Locale.to(), },
Opt { sho: 0u8, lon: "map-ascii", has: Arg::No, num: CmdOp::MapAscii.to(), },
Opt { sho: b'm', lon: "max-line-bytes",has: Arg::No, num: CmdOp::MaxLineBytes.to(), },
Opt { sho: b'?', lon: "query", has: Arg::Yes, num: CmdOp::Query.to(), },
Opt { sho: b'V', lon: "version", has: Arg::No, num: CmdOp::Version.to(), },
Opt { sho: b'w', lon: "words", has: Arg::No, num: CmdOp::Words.to(), },
];
#[rustfmt::skip]
const OPT_ARY_SHO_IDX: [(u8,usize);10] = [
(b'?',9),(b'H',4),(b'V',10),(b'X',0),(b'a',1),(b'b',2),(b'c',3),(b'l',5),(b'm',8),(b'w',11),];
#[derive(Debug, Default, PartialEq, Eq)]
pub struct CmdOptConf {
pub prog_name: String,
//
pub flg_all: bool,
pub flg_bytes: bool,
pub flg_chars: bool,
pub flg_lines: bool,
pub flg_map_ascii: bool,
pub flg_max_line_bytes: bool,
pub flg_words: bool,
pub opt_locale: OptLocaleLoc,
pub opt_query: Option<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())),
}
}