diff options
author | Garrett Squire <garrettsquire@gmail.com> | 2016-09-26 20:56:15 -0700 |
---|---|---|
committer | Garrett Squire <garrettsquire@gmail.com> | 2016-09-27 16:14:53 -0700 |
commit | babe80d498675b1cb8e649a96cf73f6cc694792d (patch) | |
tree | e4b1a9d241c857bfb4ebfc933f9e32a176cacb02 /src/args.rs | |
parent | 3e892a7a80e86d5e57e95626788c10e23d4221cf (diff) |
add a max-depth option for directory traversal
CR and add integration test
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/args.rs b/src/args.rs index 2a825e29..0f49e53e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -136,6 +136,10 @@ Less common options: -L, --follow Follow symlinks. + --maxdepth NUM + Descend at most NUM directories below the command line arguments. + A value of zero only searches the starting-points themselves. + --mmap Search using memory maps when possible. This is enabled by default when ripgrep thinks it will be faster. (Note that mmap searching @@ -222,6 +226,7 @@ pub struct RawArgs { flag_invert_match: bool, flag_line_number: bool, flag_fixed_strings: bool, + flag_maxdepth: Option<usize>, flag_mmap: bool, flag_no_heading: bool, flag_no_ignore: bool, @@ -272,6 +277,7 @@ pub struct Args { invert_match: bool, line_number: bool, line_per_match: bool, + maxdepth: Option<usize>, mmap: bool, no_ignore: bool, no_ignore_parent: bool, @@ -399,6 +405,7 @@ impl RawArgs { invert_match: self.flag_invert_match, line_number: !self.flag_no_line_number && self.flag_line_number, line_per_match: self.flag_vimgrep, + maxdepth: self.flag_maxdepth, mmap: mmap, no_ignore: no_ignore, no_ignore_parent: @@ -681,7 +688,10 @@ impl Args { /// Create a new recursive directory iterator at the path given. pub fn walker(&self, path: &Path) -> Result<walk::Iter> { - let wd = WalkDir::new(path).follow_links(self.follow); + let mut wd = WalkDir::new(path).follow_links(self.follow); + if let Some(maxdepth) = self.maxdepth { + wd = wd.max_depth(maxdepth); + } let mut ig = Ignore::new(); // Only register ignore rules if this is a directory. If it's a file, // then it was explicitly given by the end user, so we always search |