From 6f0eac5a8c00eb698cd2d0dd9fd662f18203e98b Mon Sep 17 00:00:00 2001 From: Shane Snover Date: Mon, 19 Apr 2021 19:18:45 -0600 Subject: [PATCH] fix: Add newline after qr code and print usage if incorrect number of args passed --- src/bin/qrencode.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bin/qrencode.rs b/src/bin/qrencode.rs index 4837828..db4abc7 100644 --- a/src/bin/qrencode.rs +++ b/src/bin/qrencode.rs @@ -1,8 +1,12 @@ use std::env; pub fn main() { - let arg = env::args().nth(1).unwrap(); - let code = qrcode::QrCode::new(arg.as_bytes()).unwrap(); + if env::args().len() == 2 { + let arg = env::args().nth(1).unwrap(); + let code = qrcode::QrCode::new(arg.as_bytes()).unwrap(); - print!("{}", code.render().dark_color("\x1b[7m \x1b[0m").light_color("\x1b[49m \x1b[0m").build()); + println!("{}", code.render().dark_color("\x1b[7m \x1b[0m").light_color("\x1b[49m \x1b[0m").build()); + } else { + println!("Usage: {} INPUT_TEXT", env::args().nth(0).unwrap()); + } }