diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-01-06 22:43:59 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-01-06 22:43:59 -0500 |
commit | b65a8c353b1d214f2b26be61b715059727ce94bb (patch) | |
tree | 08455fe88d1dc813c38261f1a633b0a31b67fd5d /src | |
parent | 95cea77625f978a21b1d923e54d13f9217f0ef30 (diff) |
Add --sort-files flag.
When used, parallelism is disabled but the results are sorted by file
path.
Closes #263
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 5 | ||||
-rw-r--r-- | src/args.rs | 8 |
2 files changed, 13 insertions, 0 deletions
@@ -158,6 +158,7 @@ fn app<F>(next_line_help: bool, doc: F) -> App<'static, 'static> .arg(flag("replace").short("r").value_name("ARG").takes_value(true)) .arg(flag("case-sensitive").short("s")) .arg(flag("smart-case").short("S")) + .arg(flag("sort-files")) .arg(flag("threads") .short("j").value_name("ARG").takes_value(true) .validator(validate_number)) @@ -426,6 +427,10 @@ lazy_static! { "Searches case insensitively if the pattern is all lowercase. \ Search case sensitively otherwise. This is overridden by \ either -s/--case-sensitive or -i/--ignore-case."); + doc!(h, "sort-files", + "Sort results by file path. Implies --threads=1.", + "Sort results by file path. Note that this currently \ + disables all parallelism and runs search in a single thread."); doc!(h, "threads", "The approximate number of threads to use.", "The approximate number of threads to use. A value of 0 (which \ diff --git a/src/args.rs b/src/args.rs index 18da6f66..6aec396b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -64,6 +64,7 @@ pub struct Args { quiet: bool, quiet_matched: QuietMatched, replace: Option<Vec<u8>>, + sort_files: bool, text: bool, threads: usize, type_list: bool, @@ -277,6 +278,9 @@ impl Args { wd.ignore(!self.no_ignore); wd.parents(!self.no_ignore_parent); wd.threads(self.threads()); + if self.sort_files { + wd.sort_by(|a, b| a.cmp(b)); + } wd } } @@ -333,6 +337,7 @@ impl<'a> ArgMatches<'a> { quiet: quiet, quiet_matched: QuietMatched::new(quiet), replace: self.replace(), + sort_files: self.is_present("sort-files"), text: self.text(), threads: try!(self.threads()), type_list: self.is_present("type-list"), @@ -654,6 +659,9 @@ impl<'a> ArgMatches<'a> { /// Returns the approximate number of threads that ripgrep should use. fn threads(&self) -> Result<usize> { + if self.is_present("sort-files") { + return Ok(1); + } let threads = try!(self.usize_of("threads")).unwrap_or(0); Ok(if threads == 0 { cmp::min(12, num_cpus::get()) |