Skip to main content

libaki_mcycle/conf/
cmd.help.rs.txt

1// WARN: This file is auto generated by flood-tide-gen
2const OPTIONS_TEXT: &str = r"Options:
3  -e, --exp <exp>   write it in the cyclic color (default: ' ([0-9A-Z]{3,}):')
4
5  -H, --help        display this help and exit
6  -V, --version     display version information and exit
7  -X <x-options>    x options. try -X help
8";
9
10#[repr(u8)]
11#[derive(Debug, PartialEq, Eq)]
12enum CmdOp {
13    Exp,
14    Help,
15    Version,
16    UcX,
17}
18
19impl CmdOp {
20    pub const fn to(self) -> OptNum {
21        self as OptNum
22    }
23}
24
25impl std::convert::From<u8> for CmdOp {
26    fn from(value: u8) -> Self {
27        match value {
28            0 => CmdOp::Exp,
29            1 => CmdOp::Help,
30            2 => CmdOp::Version,
31            3 => CmdOp::UcX,
32            _ => unreachable!(),
33        }
34    }
35}
36
37#[rustfmt::skip]
38const OPT_ARY: [Opt;4] = [
39    Opt { sho: b'X', lon: "",              has: Arg::Yes, num: CmdOp::UcX.to(), },
40    Opt { sho: b'e', lon: "exp",           has: Arg::Yes, num: CmdOp::Exp.to(), },
41    Opt { sho: b'H', lon: "help",          has: Arg::No,  num: CmdOp::Help.to(), },
42    Opt { sho: b'V', lon: "version",       has: Arg::No,  num: CmdOp::Version.to(), },
43];
44
45#[rustfmt::skip]
46const OPT_ARY_SHO_IDX: [(u8,usize);4] = [
47(b'H',2),(b'V',3),(b'X',0),(b'e',1),];
48
49#[derive(Debug, Default, PartialEq, Eq)]
50pub struct CmdOptConf {
51    pub prog_name: String,
52    //
53    pub opt_exp: String,
54    pub flg_help: bool,
55    pub flg_version: bool,
56    pub opt_uc_x: Vec<OptUcXParam>,
57    //
58    pub arg_params: Vec<String>,
59}
60
61impl flood_tide::HelpVersion for CmdOptConf {
62    fn is_help(&self) -> bool {
63        self.flg_help
64    }
65    fn is_version(&self) -> bool {
66        self.flg_version
67    }
68}
69
70fn value_to_type<T>(nv: &NameVal<'_>) -> Result<T, OptParseError>
71where
72    T: std::str::FromStr,
73    <T as std::str::FromStr>::Err: std::fmt::Display,
74{
75    match nv.val {
76        Some(x) => match x.parse::<T>() {
77            Ok(d) => Ok(d),
78            Err(err) => Err(OptParseError::invalid_option_argument(
79                &nv.opt.lon_or_sho(),
80                &err.to_string(),
81            )),
82        },
83        None => Err(OptParseError::missing_option_argument(&nv.opt.lon_or_sho())),
84    }
85}