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
use clap::{App, Arg};
pub struct ConvArgs {
pub ph: f64,
pub custom: bool,
pub calibration: Option<[f64; 2]>,
}
impl ConvArgs {
pub fn parse() -> Self {
let matches = App::new("conph")
.author("Peter Dunne")
.version("0.1.0")
.about("Calculates 2D magnetic fields")
.arg(
Arg::with_name("ph")
.help("pH measured")
.index(1)
.required(true)
.takes_value(true),
)
.arg(
Arg::with_name("temperature")
.help("temperature of measurement")
.short("t")
.long("temperature")
.takes_value(true),
)
.arg(
Arg::with_name("custom")
.short("c")
.long("custom")
.help("Custom Input")
.requires_all(&["slope", "offset"]),
)
.arg(
Arg::with_name("slope")
.short("s")
.long("slope")
.help("Slope")
.takes_value(true)
.requires_all(&["custom", "offset"]),
)
.arg(
Arg::with_name("offset")
.short("o")
.long("offset")
.help("offset")
.takes_value(true)
.requires_all(&["custom", "slope"]),
)
.get_matches();
let ph = matches
.value_of("ph")
.unwrap_or_default()
.parse::<f64>()
.unwrap();
let custom = matches.is_present("custom");
let calibration = if custom == true {
let slope = matches
.value_of("slope")
.unwrap_or_default()
.parse::<f64>()
.unwrap();
let offset = matches
.value_of("offset")
.unwrap_or_default()
.parse::<f64>()
.unwrap();
Some([slope, offset])
} else {
None
};
Self {
ph,
custom,
calibration,
}
}
}