summaryrefslogtreecommitdiffstats
path: root/vendor/xflags-macros/src/ast.rs
blob: 7fb9df1e124a108356871330646fa5096274e719 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#[derive(Debug)]
pub(crate) struct XFlags {
    pub(crate) src: Option<String>,
    pub(crate) cmd: Cmd,
}

impl XFlags {
    pub fn is_anon(&self) -> bool {
        self.cmd.name.is_empty()
    }
}

#[derive(Debug)]
pub(crate) struct Cmd {
    pub(crate) name: String,
    pub(crate) doc: Option<String>,
    pub(crate) args: Vec<Arg>,
    pub(crate) flags: Vec<Flag>,
    pub(crate) subcommands: Vec<Cmd>,
    pub(crate) default: bool,
    pub(crate) idx: u8,
}

#[derive(Debug)]
pub(crate) struct Arg {
    pub(crate) arity: Arity,
    pub(crate) doc: Option<String>,
    pub(crate) val: Val,
}

#[derive(Debug)]
pub(crate) struct Flag {
    pub(crate) arity: Arity,
    pub(crate) name: String,
    pub(crate) short: Option<String>,
    pub(crate) doc: Option<String>,
    pub(crate) val: Option<Val>,
}

impl Flag {
    pub(crate) fn is_help(&self) -> bool {
        self.name == "help"
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Arity {
    Optional,
    Required,
    Repeated,
}

#[derive(Debug)]
pub(crate) struct Val {
    pub(crate) name: String,
    pub(crate) ty: Ty,
}

#[derive(Debug)]
pub(crate) enum Ty {
    PathBuf,
    OsString,
    FromStr(String),
}