From 78a773e9596e7af2d053b3fb79b38781211b9220 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Fri, 3 Mar 2023 00:20:59 +0400 Subject: add option to select non-matching lines --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 33de082..d7d15a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,10 @@ struct Config { #[arg(short, long)] ignore_case: bool, + /// Selects non-matching lines + #[arg(short = 'v', long)] + invert_match: bool, + /// Matches only whole words #[arg(short, long)] word_regexp: bool, @@ -52,7 +56,9 @@ fn run(config: Config) -> Result<(), Box> { }; for line in reader.lines().map(|l| l.unwrap()) { - if !trgrep::contains_pattern(&line, &config.pattern, config.ignore_case, config.word_regexp) { + let match_flag = trgrep::contains_pattern(&line, &config.pattern, config.ignore_case, config.word_regexp); + let match_flag = if config.invert_match { !match_flag } else { match_flag }; + if !match_flag { continue; } println!("{line}"); -- cgit v1.2.3-18-g5258