diff options
author | Joursoir <chat@joursoir.net> | 2023-03-05 17:34:00 +0400 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2023-03-13 01:28:46 +0400 |
commit | 0cc3793aefa03222624b297230650d1391edd645 (patch) | |
tree | c4bec7a734cbd94c1ccb3120b94810c141776bfe | |
parent | 7b612f0f1854eb164b658547ac57be6ab9dad338 (diff) | |
download | trgrep-0cc3793aefa03222624b297230650d1391edd645.tar.gz trgrep-0cc3793aefa03222624b297230650d1391edd645.tar.bz2 trgrep-0cc3793aefa03222624b297230650d1391edd645.zip |
add option to display only the filenames of files that contain matches
-rw-r--r-- | src/main.rs | 11 |
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 { |