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
|
#![warn(missing_docs, rust_2018_compatibility, rust_2018_idioms, unused)]
//! Reads OTP configuration from a QR code and writes it to an OTP slot on a Nitrokey device.
use std::process;
#[derive(Debug)]
struct Options {
slot: u8,
file: Option<String>,
name: Option<String>,
}
fn parse_options() -> Result<Options, i32> {
let mut options = Options {
slot: 0,
file: None,
name: None,
};
let mut parser = argparse::ArgumentParser::new();
parser.set_description(
"Reads OTP configuration from a QR code and writes it to an OTP slot on a Nitrokey device.",
);
parser.refer(&mut options.slot).required().add_argument(
"slot",
argparse::Store,
"The slot to write the OTP data to",
);
parser.refer(&mut options.file).add_argument(
"file",
argparse::StoreOption,
"The file to read the QR code from",
);
parser.refer(&mut options.name).add_option(
&["-n", "--name"],
argparse::StoreOption,
"The name to store in the OTP slot",
);
parser.parse_args()?;
drop(parser);
Ok(options)
}
fn main() {
let status = match parse_options() {
Ok(_) => 0,
Err(err) => err,
};
process::exit(status);
}
|