summaryrefslogtreecommitdiffstats
path: root/src/app.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-08-25 22:53:27 -0400
committerAndrew Gallant <jamslam@gmail.com>2018-08-26 18:42:25 -0400
commit40e310a9f9e21929acb5b0eb364ffad51df80608 (patch)
treeea3623dc04ea877e68aad37e09ef162b27781e9c /src/app.rs
parent510f15f4da46ca8553f93e9b82346794a6dc7dd9 (diff)
ripgrep: add --sort and --sortr flags
These flags each accept one of five choices: none, path, modified, accessed or created. The value indicates how the results are sorted. For --sort, results are sorted in ascending order where as for --sortr, results are sorted in descending order. Closes #404
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs81
1 files changed, 78 insertions, 3 deletions
diff --git a/src/app.rs b/src/app.rs
index 1394f9d2..19306c2c 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -600,6 +600,8 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_search_zip(&mut args);
flag_smart_case(&mut args);
flag_sort_files(&mut args);
+ flag_sort(&mut args);
+ flag_sortr(&mut args);
flag_stats(&mut args);
flag_text(&mut args);
flag_threads(&mut args);
@@ -1923,8 +1925,10 @@ This overrides the -s/--case-sensitive and -i/--ignore-case flags.
}
fn flag_sort_files(args: &mut Vec<RGArg>) {
- const SHORT: &str = "Sort results by file path. Implies --threads=1.";
+ const SHORT: &str = "DEPRECATED";
const LONG: &str = long!("\
+DEPRECATED: Use --sort or --sortr instead.
+
Sort results by file path. Note that this currently disables all parallelism
and runs search in a single thread.
@@ -1932,12 +1936,83 @@ This flag can be disabled with --no-sort-files.
");
let arg = RGArg::switch("sort-files")
.help(SHORT).long_help(LONG)
- .overrides("no-sort-files");
+ .hidden()
+ .overrides("no-sort-files")
+ .overrides("sort")
+ .overrides("sortr");
args.push(arg);
let arg = RGArg::switch("no-sort-files")
.hidden()
- .overrides("sort-files");
+ .overrides("sort-files")
+ .overrides("sort")
+ .overrides("sortr");
+ args.push(arg);
+}
+
+fn flag_sort(args: &mut Vec<RGArg>) {
+ const SHORT: &str =
+ "Sort results in ascending order. Implies --threads=1.";
+ const LONG: &str = long!("\
+This flag enables sorting of results in ascending order. The possible values
+for this flag are:
+
+ path Sort by file path.
+ modified Sort by the last modified time on a file.
+ accessed Sort by the last accessed time on a file.
+ created Sort by the cretion time on a file.
+ none Do not sort results.
+
+If the sorting criteria isn't available on your system (for example, creation
+time is not available on ext4 file systems), then ripgrep will attempt to
+detect this and print an error without searching any results. Otherwise, the
+sort order is unspecified.
+
+To sort results in reverse or descending order, use the --sortr flag. Also,
+this flag overrides --sortr.
+
+Note that sorting results currently always forces ripgrep to abandon
+parallelism and run in a single thread.
+");
+ let arg = RGArg::flag("sort", "SORTBY")
+ .help(SHORT).long_help(LONG)
+ .possible_values(&["path", "modified", "accessed", "created", "none"])
+ .overrides("sortr")
+ .overrides("sort-files")
+ .overrides("no-sort-files");
+ args.push(arg);
+}
+
+fn flag_sortr(args: &mut Vec<RGArg>) {
+ const SHORT: &str =
+ "Sort results in descending order. Implies --threads=1.";
+ const LONG: &str = long!("\
+This flag enables sorting of results in descending order. The possible values
+for this flag are:
+
+ path Sort by file path.
+ modified Sort by the last modified time on a file.
+ accessed Sort by the last accessed time on a file.
+ created Sort by the cretion time on a file.
+ none Do not sort results.
+
+If the sorting criteria isn't available on your system (for example, creation
+time is not available on ext4 file systems), then ripgrep will attempt to
+detect this and print an error without searching any results. Otherwise, the
+sort order is unspecified.
+
+To sort results in ascending order, use the --sort flag. Also, this flag
+overrides --sort.
+
+Note that sorting results currently always forces ripgrep to abandon
+parallelism and run in a single thread.
+");
+ let arg = RGArg::flag("sortr", "SORTBY")
+ .help(SHORT).long_help(LONG)
+ .possible_values(&["path", "modified", "accessed", "created", "none"])
+ .overrides("sort")
+ .overrides("sort-files")
+ .overrides("no-sort-files");
args.push(arg);
}