cli: add --include-zero flag

This flag, when used in conjunction with --count or --count-matches,
will print a result for each file searched even if there were zero
matches in that file. This is off by default but can be enabled to make
ripgrep behave more like grep.

This also clarifies some of the defaults for the
grep-printer::SummaryBuilder type.

Closes #1370, Closes #1405
This commit is contained in:
Collin Styles
2019-10-16 19:03:00 -07:00
committed by Andrew Gallant
parent 4628d77808
commit a070722ff2
6 changed files with 56 additions and 1 deletions

View File

@@ -578,6 +578,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_ignore_case(&mut args);
flag_ignore_file(&mut args);
flag_ignore_file_case_insensitive(&mut args);
flag_include_zero(&mut args);
flag_invert_match(&mut args);
flag_json(&mut args);
flag_line_buffered(&mut args);
@@ -1373,6 +1374,17 @@ This flag can be disabled with the --no-ignore-file-case-insensitive flag.
args.push(arg);
}
fn flag_include_zero(args: &mut Vec<RGArg>) {
const SHORT: &str = "Include files with zero matches in summary";
const LONG: &str = long!("\
When used with --count or --count-matches, print the number of matches for
each file even if there were zero matches. This is disabled by default but can
be enabled to make ripgrep behave more like grep.
");
let arg = RGArg::switch("include-zero").help(SHORT).long_help(LONG);
args.push(arg);
}
fn flag_invert_match(args: &mut Vec<RGArg>) {
const SHORT: &str = "Invert matching.";
const LONG: &str = long!("\

View File

@@ -812,6 +812,7 @@ impl ArgMatches {
.stats(self.stats())
.path(self.with_filename(paths))
.max_matches(self.max_count()?)
.exclude_zero(!self.is_present("include-zero"))
.separator_field(b":".to_vec())
.separator_path(self.path_separator()?)
.path_terminator(self.path_terminator());