From 0cc3793aefa03222624b297230650d1391edd645 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sun, 5 Mar 2023 17:34:00 +0400 Subject: add option to display only the filenames of files that contain matches --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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> { - 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> { 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 { -- cgit v1.2.3-18-g5258