From 6cfc449c240a9280c1d81f054c77d61ae0ca4b44 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Thu, 27 Oct 2022 00:38:53 -0400 Subject: [PATCH] Fixed reading stdin when no filename is passed --- rust/timetracker/src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rust/timetracker/src/main.rs b/rust/timetracker/src/main.rs index 4eed087..f4e4816 100644 --- a/rust/timetracker/src/main.rs +++ b/rust/timetracker/src/main.rs @@ -20,23 +20,19 @@ fn main() { let end = Regex::new(r"End\s+(?P.*)\s*$").unwrap(); let category = Regex::new(r"\[(?P.*)\]\s+(?P.*)\s*$").unwrap(); let do_process = Regex::new(r"do_process").unwrap(); - let dp_opts = Regex::new(r"^(-d|--do-process)").unwrap(); let mut dp: bool = false; let mut categories: Vec = Vec::new(); - // Process options - let mut params: Vec = env::args().collect(); + // Determine if we'r the do_process variant + let params: Vec = env::args().collect(); if do_process.is_match(¶ms[0]) { dp = true; - } else if dp_opts.is_match(¶ms[1]) { - dp = true; - params.remove(1); }; // Process the file (stdin or file argument) - let input: Option<_> = Some(¶ms[1]); + let input = env::args().nth(1); let reader: Box = match input { None => Box::new(BufReader::new(io::stdin())), Some(filename) => Box::new(BufReader::new(fs::File::open(filename).unwrap()))