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
#[derive(Debug, Clone)]
pub enum ArgValue {
Bool(bool),
Int(i64),
Float(f64),
String(String)
}
#[derive(Debug, Clone, PartialEq)]
pub enum ArgType {
Bool,
Int,
Float,
String
}
impl Default for ArgType {
fn default() -> Self {
ArgType::Bool
}
}
#[derive(Debug)]
pub struct Parameter {
pub(super) name: String,
pub(super) value_type: ArgType,
pub(super) description: String
}
#[derive(Default)]
pub struct ParameterBuilder<'a> {
pub(super) name: String,
pub(super) aliases: Vec<String>,
pub(super) description: Option<&'a str>,
pub(super) value_type: ArgType
}
impl Parameter {
pub fn with_name(name: &str) -> ParameterBuilder {
ParameterBuilder {
name: name.to_string(),
..
Default::default()
}
}
}
impl<'a> ParameterBuilder<'a> {
pub fn value_type(mut self, t: ArgType) -> Self {
self.value_type = t;
self
}
pub fn alias(mut self, alias: &'a str) -> Self {
self.aliases.push(alias.into());
self
}
pub fn description(mut self, text: &'a str) -> Self {
self.description = Some(text);
self
}
}