summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2023-03-03 00:20:59 +0400
committerJoursoir <chat@joursoir.net>2023-03-03 00:20:59 +0400
commit78a773e9596e7af2d053b3fb79b38781211b9220 (patch)
tree22cd8b01b2cb203d87a797801d1e40ea3a7b15e7
parent0fd76b8e90470b99f3e5c968b65562fde56d0c3e (diff)
downloadtrgrep-78a773e9596e7af2d053b3fb79b38781211b9220.tar.gz
trgrep-78a773e9596e7af2d053b3fb79b38781211b9220.tar.bz2
trgrep-78a773e9596e7af2d053b3fb79b38781211b9220.zip
add option to select non-matching lines
-rw-r--r--src/main.rs8
1 files changed, 7 insertions, 1 deletions
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<dyn Error>> {
};
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}");