diff options
author | Daniel Luz <dev@mernen.com> | 2016-11-19 21:48:59 -0200 |
---|---|---|
committer | Daniel Luz <dev@mernen.com> | 2016-11-19 21:48:59 -0200 |
commit | bd3e7eedb1d8698a46e18afd2041e675f6597947 (patch) | |
tree | 327d6c6f2f30174ae754232480bc656ac5713105 /src/search_buffer.rs | |
parent | 1e6c2ac8e374c9f45204ecce1ddd96842ed26d15 (diff) |
Add --files-without-matches flag.
Performs the opposite of --files-with-matches: only shows paths of
files that contain zero matches.
Closes #138
Diffstat (limited to 'src/search_buffer.rs')
-rw-r--r-- | src/search_buffer.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/search_buffer.rs b/src/search_buffer.rs index c7c3bca0..16a161e1 100644 --- a/src/search_buffer.rs +++ b/src/search_buffer.rs @@ -61,6 +61,15 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> { self } + /// If enabled, searching will print the path of files that *don't* match + /// the given pattern. + /// + /// Disabled by default. + pub fn files_without_matches(mut self, yes: bool) -> Self { + self.opts.files_without_matches = yes; + self + } + /// Set the end-of-line byte used by this searcher. pub fn eol(mut self, eol: u8) -> Self { self.opts.eol = eol; @@ -133,6 +142,9 @@ impl<'a, W: Send + Terminal> BufferSearcher<'a, W> { if self.opts.files_with_matches && self.match_count > 0 { self.printer.path(self.path); } + if self.opts.files_without_matches && self.match_count == 0 { + self.printer.path(self.path); + } self.match_count } @@ -278,6 +290,14 @@ and exhibited clearly, with a label attached.\ } #[test] + fn files_without_matches() { + let (count, out) = search( + "zzzz", SHERLOCK, |s| s.files_without_matches(true)); + assert_eq!(0, count); + assert_eq!(out, "/baz.rs\n"); + } + + #[test] fn max_count() { let (count, out) = search( "Sherlock", SHERLOCK, |s| s.max_count(Some(1))); |