diff options
author | Andrew Schwartzmeyer <andrew@schwartzmeyer.com> | 2016-09-23 19:06:34 -0700 |
---|---|---|
committer | Andrew Schwartzmeyer <andrew@schwartzmeyer.com> | 2016-09-24 21:40:17 -0700 |
commit | a8f3d9e87e7e9192a9c1815da7c07d4522ccc1b2 (patch) | |
tree | 27dc814fa92f1f56359dfe75b281cc42fff2f376 /src/args.rs | |
parent | 1595f0faf594be5d303b1783857d23a0fda74230 (diff) |
Add --files-with-matches flag.
Closes #26.
Acts like --count but emits only the paths of files with matches,
suitable for piping to xargs. Both mmap and no-mmap searches terminate
after the first match is found. Documentation updated and tests added.
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index 99e01fdd..1d3e8812 100644 --- a/src/args.rs +++ b/src/args.rs @@ -47,6 +47,7 @@ rg recursively searches your current directory for a regex pattern. Common options: -a, --text Search binary files as if they were text. -c, --count Only show count of line matches for each file. + -l, --files-with-matches Only show path of each file with matches. --color WHEN Whether to use coloring in match. Valid values are never, always or auto. [default: auto] @@ -199,6 +200,7 @@ pub struct RawArgs { flag_context: usize, flag_context_separator: String, flag_count: bool, + flag_files_with_matches: bool, flag_debug: bool, flag_files: bool, flag_follow: bool, @@ -246,6 +248,7 @@ pub struct Args { column: bool, context_separator: Vec<u8>, count: bool, + files_with_matches: bool, eol: u8, files: bool, follow: bool, @@ -370,6 +373,7 @@ impl RawArgs { column: self.flag_column, context_separator: unescape(&self.flag_context_separator), count: self.flag_count, + files_with_matches: self.flag_files_with_matches, eol: eol, files: self.flag_files, follow: self.flag_follow, @@ -554,7 +558,7 @@ impl Args { /// to the writer given. pub fn out(&self) -> Out { let mut out = Out::new(self.color); - if self.heading && !self.count { + if self.heading && !self.count && !self.files_with_matches { out = out.file_separator(b"".to_vec()); } else if self.before_context > 0 || self.after_context > 0 { out = out.file_separator(self.context_separator.clone()); @@ -608,6 +612,7 @@ impl Args { .after_context(self.after_context) .before_context(self.before_context) .count(self.count) + .files_with_matches(self.files_with_matches) .eol(self.eol) .line_number(self.line_number) .invert_match(self.invert_match) @@ -626,6 +631,7 @@ impl Args { ) -> BufferSearcher<'a, W> { BufferSearcher::new(printer, grep, path, buf) .count(self.count) + .files_with_matches(self.files_with_matches) .eol(self.eol) .line_number(self.line_number) .invert_match(self.invert_match) |