From 5b5d87966e6dfbd8cef3bcac9546664590d43d9e Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 7 Jan 2019 19:33:11 +0000 Subject: Implement argument handling according to spec --- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e257956..04140ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,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, + name: Option, +} + +fn parse_options() -> Result { + 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() { - println!("nitrocli-otp-qr"); + let status = match parse_options() { + Ok(_) => 0, + Err(err) => err, + }; + process::exit(status); } -- cgit v1.2.1