From 9faef460fa13857ca26b4447b9d627bb76e9bbd9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 1 Mar 2018 23:58:25 +0100 Subject: Clean up condition for getting file path from argument Instead of the convoluted hard-to-read `hide_password &&` nonsense, give ourselves a way to express the condition in terms of the argument _not_ being one of our accepted options (only `-i`). This ensures that we either capture the filename in the last argument or use STDIN. --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 69f7736..7411c1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,15 +92,18 @@ fn is_password_line(line: &str) -> bool { fn main() { let args: Vec = env::args().collect(); + let options = ["-i"]; + let hide_password = match args.get(1) { Some(arg) if arg == "-i" => true, Some(_) => false, None => false, }; - let input = if hide_password && args.len() > 2 || - !hide_password && args.len() > 1 { - &args[args.len() - 1] + let last_arg = &args[args.len() - 1]; + let input = if args.len() > 1 && + !options.contains(&last_arg.as_ref()) { + last_arg } else { "-" }; -- cgit v1.2.3