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,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<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(())
}