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
use bpaf::*;
use std::path::PathBuf;
#[allow(dead_code)]
#[derive(Debug, Clone)]
struct Out {
debug: bool,
verbose: usize,
speed: f64,
output: PathBuf,
nb_cars: u32,
files_to_process: Vec<PathBuf>,
}
fn main() {
let debug = short('d')
.long("debug")
.help("Activate debug mode")
.switch();
let verbose = short('v')
.long("verbose")
.help("Increase the verbosity\nYou can specify it up to 3 times\neither as -v -v -v or as -vvv")
.req_flag(())
.many()
.map(|xs| xs.len())
.guard(|&x| x <= 3, "It doesn't get any more verbose than this");
let speed = short('s')
.long("speed")
.help("Set speed")
.argument("SPEED")
.from_str()
.fallback(42.0);
let output = short('o')
.long("output")
.help("output file")
.argument_os("OUTPUT")
.map(PathBuf::from);
let nb_cars = short('n').long("nb-cars").argument("N").from_str();
let file_to_proces = short('f')
.long("file")
.help("File to process")
.argument_os("FILE")
.map(PathBuf::from);
let files_to_process = file_to_proces.many();
let opt = construct!(Out {
debug,
verbose,
speed,
output,
nb_cars,
files_to_process
})
.to_options()
.run();
println!("{:#?}", opt);
}