From b2d0865f432a38e986e9d404db9e2c560c9c596e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Tue, 21 Jan 2020 01:04:02 +0800 Subject: [PATCH] v 0.1.1 --- Cargo.toml | 3 ++- README.md | 10 +++++++++- src/main.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 385e9f6..c85444f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qr" -version = "0.1.0" +version = "0.1.1" authors = ["Hatter Jiang "] edition = "2018" readme = "README.md" @@ -11,3 +11,4 @@ license = "MIT" [dependencies] qrcode = { version = "0.11.2", default-features = false } +clap = "2.33.0" diff --git a/README.md b/README.md index b9b74e8..f9e29b3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # qr -qr \ No newline at end of file +``` +cargo install qr +``` + + +``` +qr 'hello world' +``` + diff --git a/src/main.rs b/src/main.rs index 8230aaa..96fbb3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,33 @@ +use clap::{Arg, App}; use qrcode::QrCode; const W: &str = " "; const B: &str = " "; -fn main() { - let code = QrCode::new(b"https://hatter.ink/").unwrap(); +fn main() -> Result<(), Box> { + let matches = App::new("QR cli") + .version("0.1.1") + .author("Hatter Jiang ") + .about("QR command line tool") + .arg(Arg::with_name("INPUT") + .help("Set the QR input") + .required(true) + .index(1)) + .get_matches(); + + let mut input: Option = None; + if let Some(input_arg) = matches.args.get("INPUT") { + if input_arg.vals.len() > 0 { + input = input_arg.vals[0].clone().into_string().ok(); + } + } + + let input_string = match input { + Some(i) => i, + None => return Ok(()), // TODO + }; + + let code = QrCode::new(input_string.as_bytes()).unwrap(); let string = code.render::() .quiet_zone(false) .module_dimensions(2, 1) @@ -40,4 +63,6 @@ fn main() { output_stirng.push_str(W); } println!("{}", output_stirng); + + Ok(()) } \ No newline at end of file