-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_line_parser.rs
183 lines (178 loc) · 5.45 KB
/
command_line_parser.rs
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0
pub struct CommandLineArguments {
pub specification: String,
pub logfile: String,
pub toml: Option<String>,
pub lazy_evaluation: bool,
pub sub_sampling: bool,
pub debug_console: bool,
pub print_leaf_segments_only: bool,
pub segmentation_setting: Option<SegmentationSetting>,
}
#[derive(Clone)]
pub struct SegmentationSetting {
pub tau_dif: usize,
pub rho_dif: f32,
pub amount: usize,
}
impl CommandLineArguments {
fn new(
specification: String,
logfile: String,
toml: Option<String>,
lazy_evaluation: bool,
sub_sampling: bool,
debug_console: bool,
print_leaf_segments_only: bool,
segmentation_setting: Option<SegmentationSetting>,
) -> CommandLineArguments {
CommandLineArguments {
specification,
logfile,
toml,
lazy_evaluation,
sub_sampling,
debug_console,
print_leaf_segments_only,
segmentation_setting,
}
}
}
pub fn parse_command_line() -> CommandLineArguments {
// Basic app information
let app = clap::App::new("Temporal Behavior Trees")
.version("0.1.0")
.about("Computes robustness and segmentation.")
.author(clap::crate_authors!("\n"));
// Define the name command line option
let specification = clap::Arg::with_name("specification")
.required(true)
.short("s")
.long("spec")
.takes_value(true)
.value_name("FILE")
.help("Get specification location");
let logfile = clap::Arg::with_name("logfile")
.required(true)
.short("f")
.long("logfile")
.takes_value(true)
.value_name("FILE")
.help("Get logfile location");
let toml = clap::Arg::with_name("toml")
.required(false)
.long("toml")
.takes_value(true)
.value_name("FILE")
.help("Create xml output file (e.g., tbt_seg_out.toml)");
let lazy_evaluation = clap::Arg::with_name("lazy_evaluation")
.required(false)
.short("l")
.long("lazy")
.takes_value(false)
.help("Activates lazy evaluation");
let sub_sampling = clap::Arg::with_name("sub_sampling")
.required(false)
.short("u")
.long("sampling")
.takes_value(false)
.help("Activates subsampling");
let debugging = clap::Arg::with_name("debugging")
.required(false)
.short("d")
.long("debug")
.takes_value(false)
.help("Activates debugging prints");
let tau_dif = clap::Arg::with_name("tau_dif")
.required(false)
.short("t")
.long("tau")
.takes_value(true)
.default_value("20000")
.value_name("TAU")
.help("Specifies tau difference for alternative segmentation");
let rho_dif = clap::Arg::with_name("rho_dif")
.required(false)
.short("r")
.long("rho")
.takes_value(true)
.default_value("50.0")
.value_name("RHO")
.help("Specifies rho difference for alternative segmentation");
let amount = clap::Arg::with_name("amount")
.required(false)
.short("a")
.long("amount")
.takes_value(true)
.default_value("3")
.value_name("UINT")
.help("Specifies number of alternative segmentations");
let children = clap::Arg::with_name("children")
.required(false)
.short("c")
.long("children")
.help("Specifies whether only leaf nodes of a segmentation shall be printed");
// Add arguments to the app to be parsed
let app = app
.arg(specification)
.arg(logfile)
.arg(toml)
.arg(lazy_evaluation)
.arg(sub_sampling)
.arg(debugging)
.arg(tau_dif)
.arg(rho_dif)
.arg(children)
.arg(amount);
// Extract the matches
let matches = app.get_matches();
// Extract data
let specification = matches
.value_of("specification")
.expect("This can't be None, since it is required")
.to_string();
let logfile = matches
.value_of("logfile")
.expect("This can't be None, since it is required")
.to_string();
let toml = matches.value_of("toml").map(|s| s.to_string());
let lazy_evaluation = matches.is_present("lazy_evaluation");
let sub_sampling = matches.is_present("sub_sampling");
let debug_console = matches.is_present("debugging");
let tau_dif = matches
.value_of("tau_dif")
.expect("This can't be None, since it is present")
.parse()
.unwrap();
let rho_dif = matches
.value_of("rho_dif")
.expect("This can't be None, since it is present")
.parse()
.unwrap();
let amount = matches
.value_of("amount")
.expect("This can't be None, since it is present")
.parse()
.unwrap();
let print_leaf_segments_only = matches.is_present("children");
let segmentation_setting = if !lazy_evaluation {
Some(SegmentationSetting {
tau_dif,
rho_dif,
amount,
})
} else {
None
};
CommandLineArguments::new(
specification,
logfile,
toml,
lazy_evaluation,
sub_sampling,
debug_console,
print_leaf_segments_only,
segmentation_setting,
)
}