libcaliph/args/
args_caliph.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2License, v. 2.0. If a copy of the MPL was not distributed with this
3file, You can obtain one at https://mozilla.org/MPL/2.0/.
4Copyright 2021 Peter Dunne */
5
6///! Read in command line arguments for `caliph` using clap
7use clap::{App, Arg};
8
9/// Command line arguments struct, infile, outfile, and silent (i.e. emit to stdout)
10pub struct CalibArgs {
11    /// pH measured for pH 4.01 buffer solution
12    pub ph4: f64,
13    /// pH measured for pH 10.01 buffer solution
14    pub ph10: f64,
15    /// temperature of measurement
16    pub temperature: f64,
17    /// Store calibration to file calib.ph
18    pub store: bool,
19}
20
21impl CalibArgs {
22    /// Parse command line arguments
23    pub fn parse() -> Self {
24        let matches = App::new("caliph")
25            .author("Peter Dunne")
26            .version("0.1.4")
27            .about("Calculates corrections from 2 point pH calibration")
28            .arg(
29                Arg::with_name("ph4")
30                    .help("pH measured for pH 4.01 buffer solution")
31                    .index(1)
32                    .required(true)
33                    .takes_value(true),
34            )
35            .arg(
36                Arg::with_name("ph10")
37                    .help("pH measured for pH 10.01 buffer solution")
38                    .index(2)
39                    .required(true)
40                    .takes_value(true),
41            )
42            .arg(
43                Arg::with_name("temperature")
44                    .help("temperature of measurement")
45                    .short("t")
46                    .long("temperature")
47                    .takes_value(true),
48            )
49            .arg(
50                Arg::with_name("store")
51                    .short("s")
52                    .long("store")
53                    .help("Store calibration to file calib.ph"),
54            )
55            .get_matches();
56
57        let ph4 = matches
58            .value_of("ph4")
59            .unwrap_or_default()
60            .parse::<f64>()
61            .unwrap();
62        let ph10 = matches
63            .value_of("ph10")
64            .unwrap_or_default()
65            .parse::<f64>()
66            .unwrap();
67
68        let temperature = if matches.is_present("temperature") {
69            matches
70                .value_of("temperature")
71                .unwrap_or_default()
72                .parse::<f64>()
73                .unwrap()
74        } else {
75            25.0_f64
76        };
77
78        let store = matches.is_present("store");
79
80        Self {
81            ph4,
82            ph10,
83            temperature,
84            store,
85        }
86    }
87}