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
use bpaf::*;
#[allow(dead_code)]
#[derive(Debug, Copy, Clone)]
struct Out {
rect: Option<Rect>,
verbose: bool,
}
#[allow(dead_code)]
#[derive(Debug, Copy, Clone)]
struct Rect {
width: usize,
height: usize,
}
fn main() {
let width = short('w')
.long("width")
.help("Width of the rectangle")
.argument::<usize>("PX");
let height = short('h')
.long("height")
.help("Height of the rectangle")
.argument::<usize>("PX");
let rect = construct!(Rect { width, height })
.group_help("Rectangle is defined by width and height in meters")
.optional();
let verbose = short('v')
.long("verbose")
.help("Print computation steps")
.switch();
let opt = construct!(Out { verbose, rect })
.to_options()
.descr("This program calculates rectangle's area")
.header("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
.footer("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
.run();
println!("{:#?}", opt);
}