summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index bc8adc1..b566f68 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -36,6 +36,10 @@ struct Config {
#[arg(short, long)]
word_regexp: bool,
+ /// Displays only the filenames of files that contain matches
+ #[arg(short = 'l', long)]
+ files_with_matches: bool,
+
/// Suppresses the display of filenames
#[arg(short = 'h', long)]
no_filename: bool,
@@ -60,7 +64,7 @@ fn main() {
}
fn run(config: Config) -> Result<(), Box<dyn Error>> {
- for file in config.files {
+ 'outer: for file in config.files {
// On-Stack Dynamic Dispatch
let (mut stdin_read, mut file_read);
@@ -80,6 +84,11 @@ fn run(config: Config) -> Result<(), Box<dyn Error>> {
continue;
}
+ if config.files_with_matches {
+ println!("{file}");
+ continue 'outer;
+ }
+
let formatted_output = if !config.no_filename && config.line_number {
format!("{}:{}:{}", file, idx + 1, line)
} else if !config.no_filename {