diff options
Diffstat (limited to 'rust-cli/grrs/src/main.rs')
| -rw-r--r-- | rust-cli/grrs/src/main.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/rust-cli/grrs/src/main.rs b/rust-cli/grrs/src/main.rs index 09e2d3a..e5ed13b 100644 --- a/rust-cli/grrs/src/main.rs +++ b/rust-cli/grrs/src/main.rs @@ -1,5 +1,4 @@ -use std::io::{BufReader, BufRead}; -use std::fs::File; +use std::fs::{File}; use::clap::Parser; #[derive(Parser)] @@ -8,14 +7,22 @@ struct Cli { path: std::path::PathBuf, } - fn main() { let args = Cli::parse(); - //println!("pattern: {}, path: {}",args.pattern, args.path.display()); + if !args.path.exists() { + eprintln!("The file at '{}' does not exist", &args.path.display()); + return; + } + if args.pattern.is_empty() { + eprintln!("No pattern was supplied, see --help"); + return; + } let file = File::open(args.path).expect("could not read file"); - let mut reader = BufReader::new(file); - for line in reader.lines() { - if line.unwrap_or_default().contains(&args.pattern) { - } + let matches = grrs::find_matches(&file, &args.pattern).unwrap(); + if matches.len() < 1 { + return; + } + for line in matches { + println!("{}", line); } } |
