v 0.1.1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "qr"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
@@ -11,3 +11,4 @@ license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
qrcode = { version = "0.11.2", default-features = false }
|
||||
clap = "2.33.0"
|
||||
|
||||
29
src/main.rs
29
src/main.rs
@@ -1,10 +1,33 @@
|
||||
use clap::{Arg, App};
|
||||
use qrcode::QrCode;
|
||||
|
||||
const W: &str = "[47m [0m";
|
||||
const B: &str = "[40m [0m";
|
||||
|
||||
fn main() {
|
||||
let code = QrCode::new(b"https://hatter.ink/").unwrap();
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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>()
|
||||
.quiet_zone(false)
|
||||
.module_dimensions(2, 1)
|
||||
@@ -40,4 +63,6 @@ fn main() {
|
||||
output_stirng.push_str(W);
|
||||
}
|
||||
println!("{}", output_stirng);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user