From f43eafeab711ea4be4a71c732228b1244466e9b4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 1 Mar 2018 22:10:25 +0100 Subject: Use `-i` argument to hide passwords Connect the `-i` argument flag to the renderer. If the arg was passed, hide passwords, otherwise show them. Change `args.first()` to `args.get(1)` because the actual first element is the command executable. Not happy with the condition I'm using here to grab the password file or the STDIN `-`. It doesn't read well at all. It all does work, but this part I want to rewrite to make it easier to read. --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index ffe6329..69f7736 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,14 +92,15 @@ fn is_password_line(line: &str) -> bool { fn main() { let args: Vec = env::args().collect(); - let hide_password = match args.first() { + let hide_password = match args.get(1) { Some(arg) if arg == "-i" => true, Some(_) => false, None => false, }; - let input = if args.len() > 1 { - &args[1] + let input = if hide_password && args.len() > 2 || + !hide_password && args.len() > 1 { + &args[args.len() - 1] } else { "-" }; @@ -127,7 +128,7 @@ fn main() { term.printline_with_cell(selection.x, selection.y, "->", knockout_cell); for (i, s) in options.iter().enumerate() { - if is_password_line(s) { + if hide_password && is_password_line(s) { term.printline(5, i + 2, "p: ") } else { term.printline(5, i + 2, s) -- cgit v1.2.3