Fixed reading stdin when no filename is passed

This commit is contained in:
Trey Blancher 2022-10-27 00:38:53 -04:00
parent fa916c7390
commit 6cfc449c24
1 changed files with 3 additions and 7 deletions

View File

@ -20,23 +20,19 @@ fn main() {
let end = Regex::new(r"End\s+(?P<action>.*)\s*$").unwrap();
let category = Regex::new(r"\[(?P<category>.*)\]\s+(?P<activity>.*)\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<String> = Vec::new();
// Process options
let mut params: Vec<String> = env::args().collect();
// Determine if we'r the do_process variant
let params: Vec<String> = env::args().collect();
if do_process.is_match(&params[0]) {
dp = true;
} else if dp_opts.is_match(&params[1]) {
dp = true;
params.remove(1);
};
// Process the file (stdin or file argument)
let input: Option<_> = Some(&params[1]);
let input = env::args().nth(1);
let reader: Box<dyn BufRead> = match input {
None => Box::new(BufReader::new(io::stdin())),
Some(filename) => Box::new(BufReader::new(fs::File::open(filename).unwrap()))