This commit is contained in:
2020-01-21 01:04:02 +08:00
parent 5222211e91
commit b2d0865f43
3 changed files with 38 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "qr" name = "qr"
version = "0.1.0" version = "0.1.1"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"
@@ -11,3 +11,4 @@ license = "MIT"
[dependencies] [dependencies]
qrcode = { version = "0.11.2", default-features = false } qrcode = { version = "0.11.2", default-features = false }
clap = "2.33.0"

View File

@@ -1,3 +1,11 @@
# qr # qr
qr ```
cargo install qr
```
```
qr 'hello world'
```

View File

@@ -1,10 +1,33 @@
use clap::{Arg, App};
use qrcode::QrCode; use qrcode::QrCode;
const W: &str = " "; const W: &str = " ";
const B: &str = " "; const B: &str = " ";
fn main() { fn main() -> Result<(), Box<dyn std::error::Error>> {
let code = QrCode::new(b"https://hatter.ink/").unwrap(); let matches = App::new("QR cli")
.version("0.1.1")
.author("Hatter Jiang <jht5945@gmail.com>")
.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<String> = 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::<char>() let string = code.render::<char>()
.quiet_zone(false) .quiet_zone(false)
.module_dimensions(2, 1) .module_dimensions(2, 1)
@@ -40,4 +63,6 @@ fn main() {
output_stirng.push_str(W); output_stirng.push_str(W);
} }
println!("{}", output_stirng); println!("{}", output_stirng);
Ok(())
} }