aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-07 19:33:11 +0000
committerRobin Krahl <me@robin-krahl.de>2019-01-11 04:36:31 +0100
commit5b5d87966e6dfbd8cef3bcac9546664590d43d9e (patch)
tree858683da84221230af14d08ac0b1b6b313fbf987
parent000ba4f00084b8b91f863f376109383aab8b6f28 (diff)
downloadnitrocli-otp-qr-5b5d87966e6dfbd8cef3bcac9546664590d43d9e.tar.gz
nitrocli-otp-qr-5b5d87966e6dfbd8cef3bcac9546664590d43d9e.tar.bz2
Implement argument handling according to spec
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs49
3 files changed, 59 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 24d0405..3f41163 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,4 +1,14 @@
[[package]]
+name = "argparse"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "nitrocli-otp-qr"
version = "0.1.0"
+dependencies = [
+ "argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+[metadata]
+"checksum argparse 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47"
diff --git a/Cargo.toml b/Cargo.toml
index bd186ec..8dec924 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,3 +10,4 @@ readme = "README.md"
license = "MIT"
[dependencies]
+argparse = "0.2"
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<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() {
- println!("nitrocli-otp-qr");
+ let status = match parse_options() {
+ Ok(_) => 0,
+ Err(err) => err,
+ };
+ process::exit(status);
}