Fixed reading stdin when no filename is passed
This commit is contained in:
parent
fa916c7390
commit
6cfc449c24
|
@ -20,23 +20,19 @@ fn main() {
|
||||||
let end = Regex::new(r"End\s+(?P<action>.*)\s*$").unwrap();
|
let end = Regex::new(r"End\s+(?P<action>.*)\s*$").unwrap();
|
||||||
let category = Regex::new(r"\[(?P<category>.*)\]\s+(?P<activity>.*)\s*$").unwrap();
|
let category = Regex::new(r"\[(?P<category>.*)\]\s+(?P<activity>.*)\s*$").unwrap();
|
||||||
let do_process = Regex::new(r"do_process").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 dp: bool = false;
|
||||||
|
|
||||||
let mut categories: Vec<String> = Vec::new();
|
let mut categories: Vec<String> = Vec::new();
|
||||||
|
|
||||||
// Process options
|
// Determine if we'r the do_process variant
|
||||||
let mut params: Vec<String> = env::args().collect();
|
let params: Vec<String> = env::args().collect();
|
||||||
if do_process.is_match(¶ms[0]) {
|
if do_process.is_match(¶ms[0]) {
|
||||||
dp = true;
|
dp = true;
|
||||||
} else if dp_opts.is_match(¶ms[1]) {
|
|
||||||
dp = true;
|
|
||||||
params.remove(1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Process the file (stdin or file argument)
|
// Process the file (stdin or file argument)
|
||||||
let input: Option<_> = Some(¶ms[1]);
|
let input = env::args().nth(1);
|
||||||
let reader: Box<dyn BufRead> = match input {
|
let reader: Box<dyn BufRead> = match input {
|
||||||
None => Box::new(BufReader::new(io::stdin())),
|
None => Box::new(BufReader::new(io::stdin())),
|
||||||
Some(filename) => Box::new(BufReader::new(fs::File::open(filename).unwrap()))
|
Some(filename) => Box::new(BufReader::new(fs::File::open(filename).unwrap()))
|
||||||
|
|
Loading…
Reference in New Issue