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
#[derive(Debug, Clone)]
pub enum ArgVal {
Bool(bool),
Str(String),
}
#[derive(Debug, Clone)]
pub struct Arg {
pub (crate) name: String,
pub (crate) long: Option<String>,
pub (crate) short: Option<char>,
pub (crate) help: String,
pub (crate) val: ArgVal,
}
impl Arg {
pub fn bool(name: &str, val: bool) -> Self {
Self {
name: String::from(name),
long: None,
short: None,
help: String::new(),
val: ArgVal::Bool(val),
}
}
pub fn str(name: &str, val: &str) -> Self {
Self {
name: String::from(name),
long: None,
short: None,
help: String::new(),
val: ArgVal::Str(String::from(val)),
}
}
pub fn long(&mut self, long: &str) -> &mut Self {
self.long = Some(String::from(long));
self
}
pub fn short(&mut self, short: char) -> &mut Self {
self.short = Some(short);
self
}
pub fn help(&mut self, help: &str) -> &mut Self {
self.help = String::from(help);
self
}
}