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
65
66
67
68
69
70
71
72
73
74
75
76
77
#[derive(Debug, Clone, PartialEq)]
pub struct Flag {
name: String,
alias: Option<String>,
description: Option<String>,
default_value: Option<String>,
accepts_value: bool,
}
impl Flag {
pub fn name(&self) -> &String {
&self.name
}
pub fn alias(&self) -> &Option<String> {
&self.alias
}
pub fn description(&self) -> &Option<String> {
&self.description
}
pub fn default_value(&self) -> &Option<String> {
&self.default_value
}
pub fn accepts_value(&self) -> bool {
self.accepts_value
}
}
impl Flag {
pub fn with_name<S: Into<String>>(name: S) -> Self {
Self {
name: name.into(),
alias: None,
description: None,
default_value: None,
accepts_value: false,
}
}
pub fn with_alias<S: Into<String>>(mut self, val: S) -> Self {
self.alias = Some(val.into());
self
}
pub fn with_description<S: Into<String>>(mut self, val: S) -> Self {
self.description = Some(val.into());
self
}
pub fn with_default_value<S: Into<String>>(mut self, val: S) -> Self {
self.default_value = Some(val.into());
self
}
pub fn accept_value(mut self) -> Self {
self.accepts_value = true;
self
}
}