summaryrefslogtreecommitdiffstats
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs1092
1 files changed, 679 insertions, 413 deletions
diff --git a/src/app.rs b/src/app.rs
index dd1e296b..7031d804 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -9,7 +9,7 @@
// is where we read clap's configuration from the end user's arguments and turn
// it into a ripgrep-specific configuration type that is not coupled with clap.
-use clap::{self, App, AppSettings, crate_authors, crate_version};
+use clap::{self, crate_authors, crate_version, App, AppSettings};
use lazy_static::lazy_static;
const ABOUT: &str = "
@@ -284,7 +284,7 @@ pub enum RGArgKind {
/// any value other than what's in this set, then clap will report an
/// error.
possible_values: Vec<&'static str>,
- }
+ },
}
impl RGArg {
@@ -317,8 +317,7 @@ impl RGArg {
/// check whether the flag is present or not. Otherwise, consumers may
/// inspect the number of times the switch is used.
fn switch(long_name: &'static str) -> RGArg {
- let claparg = Arg::with_name(long_name)
- .long(long_name);
+ let claparg = Arg::with_name(long_name).long(long_name);
RGArg {
claparg: claparg,
name: long_name,
@@ -361,7 +360,7 @@ impl RGArg {
value_name: value_name,
multiple: false,
possible_values: vec![],
- }
+ },
}
}
@@ -370,7 +369,7 @@ impl RGArg {
/// This panics if this arg isn't a switch or a flag.
fn short(mut self, name: &'static str) -> RGArg {
match self.kind {
- RGArgKind::Positional{..} => panic!("expected switch or flag"),
+ RGArgKind::Positional { .. } => panic!("expected switch or flag"),
RGArgKind::Switch { ref mut short, .. } => {
*short = Some(name);
}
@@ -450,11 +449,12 @@ impl RGArg {
/// appropriate documentation for the choices in the "long" help text.
fn possible_values(mut self, values: &[&'static str]) -> RGArg {
match self.kind {
- RGArgKind::Positional{..} => panic!("expected flag"),
- RGArgKind::Switch{..} => panic!("expected flag"),
+ RGArgKind::Positional { .. } => panic!("expected flag"),
+ RGArgKind::Switch { .. } => panic!("expected flag"),
RGArgKind::Flag { ref mut possible_values, .. } => {
*possible_values = values.to_vec();
- self.claparg = self.claparg
+ self.claparg = self
+ .claparg
.possible_values(values)
.hide_possible_values(true);
}
@@ -475,9 +475,9 @@ impl RGArg {
/// This panics if this arg is not a flag.
fn allow_leading_hyphen(mut self) -> RGArg {
match self.kind {
- RGArgKind::Positional{..} => panic!("expected flag"),
- RGArgKind::Switch{..} => panic!("expected flag"),
- RGArgKind::Flag {..} => {
+ RGArgKind::Positional { .. } => panic!("expected flag"),
+ RGArgKind::Switch { .. } => panic!("expected flag"),
+ RGArgKind::Flag { .. } => {
self.claparg = self.claparg.allow_hyphen_values(true);
}
}
@@ -532,7 +532,9 @@ impl RGArg {
// We add an extra space to long descriptions so that a blank line is inserted
// between flag descriptions in --help output.
macro_rules! long {
- ($lit:expr) => { concat!($lit, " ") }
+ ($lit:expr) => {
+ concat!($lit, " ")
+ };
}
/// Generate a sequence of all positional and flag arguments.
@@ -642,7 +644,8 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
fn arg_pattern(args: &mut Vec<RGArg>) {
const SHORT: &str = "A regular expression used for searching.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
A regular expression used for searching. To match a pattern beginning with a
dash, use the -e/--regexp flag.
@@ -654,36 +657,49 @@ You can also use the special '--' delimiter to indicate that no more flags
will be provided. Namely, the following is equivalent to the above:
rg -- -foo
-");
+"
+ );
let arg = RGArg::positional("pattern", "PATTERN")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.required_unless(&[
- "file", "files", "regexp", "type-list", "pcre2-version",
+ "file",
+ "files",
+ "regexp",
+ "type-list",
+ "pcre2-version",
]);
args.push(arg);
}
fn arg_path(args: &mut Vec<RGArg>) {
const SHORT: &str = "A file or directory to search.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
A file or directory to search. Directories are searched recursively. Paths \
specified on the command line override glob and ignore rules. \
-");
+"
+ );
let arg = RGArg::positional("path", "PATH")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.multiple();
args.push(arg);
}
fn flag_after_context(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show NUM lines after each match.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show NUM lines after each match.
This overrides the --context flag.
-");
- let arg = RGArg::flag("after-context", "NUM").short("A")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::flag("after-context", "NUM")
+ .short("A")
+ .help(SHORT)
+ .long_help(LONG)
.number()
.overrides("context");
args.push(arg);
@@ -691,7 +707,8 @@ This overrides the --context flag.
fn flag_auto_hybrid_regex(args: &mut Vec<RGArg>) {
const SHORT: &str = "Dynamically use PCRE2 if necessary.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When this flag is used, ripgrep will dynamically choose between supported regex
engines depending on the features used in a pattern. When ripgrep chooses a
regex engine, it applies that choice for every regex provided to ripgrep (e.g.,
@@ -717,9 +734,11 @@ to transparently support more advanced regex features like look-around and
backreferences without explicitly needing to enable them.
This flag can be disabled with --no-auto-hybrid-regex.
-");
+"
+ );
let arg = RGArg::switch("auto-hybrid-regex")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-auto-hybrid-regex")
.overrides("pcre2")
.overrides("no-pcre2");
@@ -735,13 +754,17 @@ This flag can be disabled with --no-auto-hybrid-regex.
fn flag_before_context(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show NUM lines before each match.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show NUM lines before each match.
This overrides the --context flag.
-");
- let arg = RGArg::flag("before-context", "NUM").short("B")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::flag("before-context", "NUM")
+ .short("B")
+ .help(SHORT)
+ .long_help(LONG)
.number()
.overrides("context");
args.push(arg);
@@ -749,7 +772,8 @@ This overrides the --context flag.
fn flag_binary(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search binary files.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Enabling this flag will cause ripgrep to search binary files. By default,
ripgrep attempts to automatically skip binary files in order to improve the
relevance of results and make the search faster.
@@ -780,9 +804,11 @@ this flag is automatically enabled.
This flag can be disabled with '--no-binary'. It overrides the '-a/--text'
flag.
-");
+"
+ );
let arg = RGArg::switch("binary")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-binary")
.overrides("text")
.overrides("no-text");
@@ -798,7 +824,8 @@ flag.
fn flag_block_buffered(args: &mut Vec<RGArg>) {
const SHORT: &str = "Force block buffering.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When enabled, ripgrep will use block buffering. That is, whenever a matching
line is found, it will be written to an in-memory buffer and will not be
written to stdout until the buffer reaches a certain size. This is the default
@@ -810,9 +837,11 @@ Forceful block buffering can be disabled with --no-block-buffered. Note that
using --no-block-buffered causes ripgrep to revert to its default behavior of
automatically detecting the buffering strategy. To force line buffering, use
the --line-buffered flag.
-");
+"
+ );
let arg = RGArg::switch("block-buffered")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-block-buffered")
.overrides("line-buffered")
.overrides("no-line-buffered");
@@ -829,7 +858,8 @@ the --line-buffered flag.
fn flag_byte_offset(args: &mut Vec<RGArg>) {
const SHORT: &str =
"Print the 0-based byte offset for each matching line.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Print the 0-based byte offset within the input file before each line of output.
If -o (--only-matching) is specified, print the offset of the matching part
itself.
@@ -839,21 +869,26 @@ of transcoding and not the original data. This applies similarly to another
transformation on the source, such as decompression or a --pre filter. Note
that when the PCRE2 regex engine is used, then UTF-8 transcoding is done by
default.
-");
- let arg = RGArg::switch("byte-offset").short("b")
- .help(SHORT).long_help(LONG);
+"
+ );
+ let arg =
+ RGArg::switch("byte-offset").short("b").help(SHORT).long_help(LONG);
args.push(arg);
}
fn flag_case_sensitive(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search case sensitively (default).";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Search case sensitively.
This overrides the -i/--ignore-case and -S/--smart-case flags.
-");
- let arg = RGArg::switch("case-sensitive").short("s")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("case-sensitive")
+ .short("s")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("ignore-case")
.overrides("smart-case");
args.push(arg);
@@ -861,7 +896,8 @@ This overrides the -i/--ignore-case and -S/--smart-case flags.
fn flag_color(args: &mut Vec<RGArg>) {
const SHORT: &str = "Controls when to use color.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
This flag controls when to use colors. The default setting is 'auto', which
means ripgrep will try to guess when to use colors. For example, if ripgrep is
printing to a terminal, then it will use colors, but if it is redirected to a
@@ -879,9 +915,11 @@ The possible values for this flag are:
When the --vimgrep flag is given to ripgrep, then the default value for the
--color flag changes to 'never'.
-");
+"
+ );
let arg = RGArg::flag("color", "WHEN")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.possible_values(&["never", "auto", "always", "ansi"])
.default_value_if("never", "vimgrep");
args.push(arg);
@@ -889,7 +927,8 @@ When the --vimgrep flag is given to ripgrep, then the default value for the
fn flag_colors(args: &mut Vec<RGArg>) {
const SHORT: &str = "Configure color settings and styles.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
This flag specifies color settings for use in the output. This flag may be
provided multiple times. Settings are applied iteratively. Colors are limited
to one of eight choices: red, blue, green, cyan, magenta, yellow, white and
@@ -922,43 +961,50 @@ or, equivalently,
Note that the the intense and nointense style flags will have no effect when
used alongside these extended color codes.
-");
+"
+ );
let arg = RGArg::flag("colors", "COLOR_SPEC")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.multiple();
args.push(arg);
}
fn flag_column(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show column numbers.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show column numbers (1-based). This only shows the column numbers for the first
match on each line. This does not try to account for Unicode. One byte is equal
to one column. This implies --line-number.
This flag can be disabled with --no-column.
-");
+"
+ );
let arg = RGArg::switch("column")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-column");
args.push(arg);
- let arg = RGArg::switch("no-column")
- .hidden()
- .overrides("column");
+ let arg = RGArg::switch("no-column").hidden().overrides("column");
args.push(arg);
}
fn flag_context(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show NUM lines before and after each match.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show NUM lines before and after each match. This is equivalent to providing
both the -B/--before-context and -A/--after-context flags with the same value.
This overrides both the -B/--before-context and -A/--after-context flags.
-");
- let arg = RGArg::flag("context", "NUM").short("C")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::flag("context", "NUM")
+ .short("C")
+ .help(SHORT)
+ .long_help(LONG)
.number()
.overrides("before-context")
.overrides("after-context");
@@ -993,7 +1039,8 @@ is still inserted. To completely disable context separators, use the
fn flag_count(args: &mut Vec<RGArg>) {
const SHORT: &str = "Only show the count of matching lines for each file.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
This flag suppresses normal output and shows the number of lines that match
the given patterns for each file searched. Each file containing a match has its
path and count printed on each line. Note that this reports the number of lines
@@ -1005,16 +1052,21 @@ path in this case.
This overrides the --count-matches flag. Note that when --count is combined
with --only-matching, then ripgrep behaves as if --count-matches was given.
-");
- let arg = RGArg::switch("count").short("c")
- .help(SHORT).long_help(LONG).overrides("count-matches");
+"
+ );
+ let arg = RGArg::switch("count")
+ .short("c")
+ .help(SHORT)
+ .long_help(LONG)
+ .overrides("count-matches");
args.push(arg);
}
fn flag_count_matches(args: &mut Vec<RGArg>) {
const SHORT: &str =
"Only show the count of individual matches for each file.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
This flag suppresses normal output and shows the number of individual
matches of the given patterns for each file searched. Each file
containing matches has its path and match count printed on each line.
@@ -1027,15 +1079,19 @@ path in this case.
This overrides the --count flag. Note that when --count is combined with
--only-matching, then ripgrep behaves as if --count-matches was given.
-");
+"
+ );
let arg = RGArg::switch("count-matches")
- .help(SHORT).long_help(LONG).overrides("count");
+ .help(SHORT)
+ .long_help(LONG)
+ .overrides("count");
args.push(arg);
}
fn flag_crlf(args: &mut Vec<RGArg>) {
const SHORT: &str = "Support CRLF line terminators (useful on Windows).";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When enabled, ripgrep will treat CRLF ('\\r\\n') as a line terminator instead
of just '\\n'.
@@ -1046,22 +1102,23 @@ may produce slightly different than desired match offsets. It is intended as a
work-around until the regex engine supports this natively.
CRLF support can be disabled with --no-crlf.
-");
+"
+ );
let arg = RGArg::switch("crlf")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-crlf")
.overrides("null-data");
args.push(arg);
- let arg = RGArg::switch("no-crlf")
- .hidden()
- .overrides("crlf");
+ let arg = RGArg::switch("no-crlf").hidden().overrides("crlf");
args.push(arg);
}
fn flag_debug(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show debug messages.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show debug messages. Please use this when filing a bug report.
The --debug flag is generally useful for figuring out why ripgrep skipped
@@ -1071,35 +1128,37 @@ skipped and why they were skipped.
To get even more debug output, use the --trace flag, which implies --debug
along with additional trace data. With --trace, the output could be quite
large and is generally more useful for development.
-");
- let arg = RGArg::switch("debug")
- .help(SHORT).long_help(LONG);
+"
+ );
+ let arg = RGArg::switch("debug").help(SHORT).long_help(LONG);
args.push(arg);
- let arg = RGArg::switch("trace")
- .hidden()
- .overrides("debug");
+ let arg = RGArg::switch("trace").hidden().overrides("debug");
args.push(arg);
}
fn flag_dfa_size_limit(args: &mut Vec<RGArg>) {
const SHORT: &str = "The upper size limit of the regex DFA.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
The upper size limit of the regex DFA. The default limit is 10M. This should
only be changed on very large regex inputs where the (slower) fallback regex
engine may otherwise be used if the limit is reached.
The argument accepts the same size suffixes as allowed in with the
--max-filesize flag.
-");
+"
+ );
let arg = RGArg::flag("dfa-size-limit", "NUM+SUFFIX?")
- .help(SHORT).long_help(LONG);
+ .help(SHORT)
+ .long_help(LONG);
args.push(arg);
}
fn flag_encoding(args: &mut Vec<RGArg>) {
const SHORT: &str = "Specify the text encoding of files to search.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Specify the text encoding that ripgrep will use on all files searched. The
default value is 'auto', which will cause ripgrep to do a best effort automatic
detection of encoding on a per-file basis. Automatic detection in this case
@@ -1114,29 +1173,34 @@ https://encoding.spec.whatwg.org/#concept-encoding-get
For more details on encoding and how ripgrep deals with it, see GUIDE.md.
This flag can be disabled with --no-encoding.
-");
- let arg = RGArg::flag("encoding", "ENCODING").short("E")
- .help(SHORT).long_help(LONG);
+"
+ );
+ let arg = RGArg::flag("encoding", "ENCODING")
+ .short("E")
+ .help(SHORT)
+ .long_help(LONG);
args.push(arg);
- let arg = RGArg::switch("no-encoding")
- .hidden()
- .overrides("encoding");
+ let arg = RGArg::switch("no-encoding").hidden().overrides("encoding");
args.push(arg);
}
fn flag_file(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search for patterns from the given file.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Search for patterns from the given file, with one pattern per line. When this
flag is used multiple times or in combination with the -e/--regexp flag,
then all patterns provided are searched. Empty pattern lines will match all
input lines, and the newline is not counted as part of the pattern.
A line is printed if and only if it matches at least one of the patterns.
-");
- let arg = RGArg::flag("file", "PATTERNFILE").short("f")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::flag("file", "PATTERNFILE")
+ .short("f")
+ .help(SHORT)
+ .long_help(LONG)
.multiple()
.allow_leading_hyphen();
args.push(arg);
@@ -1144,12 +1208,15 @@ A line is printed if and only if it matches at least one of the patterns.
fn flag_files(args: &mut Vec<RGArg>) {
const SHORT: &str = "Print each file that would be searched.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Print each file that would be searched without actually performing the search.
This is useful to determine whether a particular file is being searched or not.
-");
+"
+ );
let arg = RGArg::switch("files")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
// This also technically conflicts with pattern, but the first file
// path will actually be in pattern.
.conflicts(&["file", "regexp", "type-list"]);
@@ -1158,81 +1225,97 @@ This is useful to determine whether a particular file is being searched or not.
fn flag_files_with_matches(args: &mut Vec<RGArg>) {
const SHORT: &str = "Only print the paths with at least one match.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Only print the paths with at least one match.
This overrides --files-without-match.
-");
- let arg = RGArg::switch("files-with-matches").short("l")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("files-with-matches")
+ .short("l")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("files-without-match");
args.push(arg);
}
fn flag_files_without_match(args: &mut Vec<RGArg>) {
const SHORT: &str = "Only print the paths that contain zero matches.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Only print the paths that contain zero matches. This inverts/negates the
--files-with-matches flag.
This overrides --files-with-matches.
-");
+"
+ );
let arg = RGArg::switch("files-without-match")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("files-with-matches");
args.push(arg);
}
fn flag_fixed_strings(args: &mut Vec<RGArg>) {
const SHORT: &str = "Treat the pattern as a literal string.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Treat the pattern as a literal string instead of a regular expression. When
this flag is used, special regular expression meta characters such as .(){}*+
do not need to be escaped.
This flag can be disabled with --no-fixed-strings.
-");
- let arg = RGArg::switch("fixed-strings").short("F")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("fixed-strings")
+ .short("F")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-fixed-strings");
args.push(arg);
- let arg = RGArg::switch("no-fixed-strings")
- .hidden()
- .overrides("fixed-strings");
+ let arg =
+ RGArg::switch("no-fixed-strings").hidden().overrides("fixed-strings");
args.push(arg);
}
fn flag_follow(args: &mut Vec<RGArg>) {
const SHORT: &str = "Follow symbolic links.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When this flag is enabled, ripgrep will follow symbolic links while traversing
directories. This is disabled by default. Note that ripgrep will check for
symbolic link loops and report errors if it finds one.
This flag can be disabled with --no-follow.
-");
- let arg = RGArg::switch("follow").short("L")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("follow")
+ .short("L")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-follow");
args.push(arg);
- let arg = RGArg::switch("no-follow")
- .hidden()
- .overrides("follow");
+ let arg = RGArg::switch("no-follow").hidden().overrides("follow");
args.push(arg);
}
fn flag_glob(args: &mut Vec<RGArg>) {
const SHORT: &str = "Include or exclude files.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Include or exclude files and directories for searching that match the given
glob. This always overrides any other ignore logic. Multiple glob flags may be
used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
it.
-");
- let arg = RGArg::flag("glob", "GLOB").short("g")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::flag("glob", "GLOB")
+ .short("g")
+ .help(SHORT)
+ .long_help(LONG)
.multiple()
.allow_leading_hyphen();
args.push(arg);
@@ -1240,14 +1323,17 @@ it.
fn flag_glob_case_insensitive(args: &mut Vec<RGArg>) {
const SHORT: &str = "Process all glob patterns case insensitively.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Process glob patterns given with the -g/--glob flag case insensitively. This
effectively treats --glob as --iglob.
This flag can be disabled with the --no-glob-case-insensitive flag.
-");
+"
+ );
let arg = RGArg::switch("glob-case-insensitive")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-glob-case-insensitive");
args.push(arg);
@@ -1259,63 +1345,72 @@ This flag can be disabled with the --no-glob-case-insensitive flag.
fn flag_heading(args: &mut Vec<RGArg>) {
const SHORT: &str = "Print matches grouped by each file.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
This flag prints the file path above clusters of matches from each file instead
of printing the file path as a prefix for each matched line. This is the
default mode when printing to a terminal.
This overrides the --no-heading flag.
-");
+"
+ );
let arg = RGArg::switch("heading")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-heading");
args.push(arg);
const NO_SHORT: &str = "Don't group matches by each file.";
- const NO_LONG: &str = long!("\
+ const NO_LONG: &str = long!(
+ "\
Don't group matches by each file. If --no-heading is provided in addition to
the -H/--with-filename flag, then file paths will be printed as a prefix for
every matched line. This is the default mode when not printing to a terminal.
This overrides the --heading flag.
-");
+"
+ );
let arg = RGArg::switch("no-heading")
- .help(NO_SHORT).long_help(NO_LONG)
+ .help(NO_SHORT)
+ .long_help(NO_LONG)
.overrides("heading");
args.push(arg);
}
fn flag_hidden(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search hidden files and directories.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Search hidden files and directories. By default, hidden files and directories
are skipped. Note that if a hidden file or a directory is whitelisted in an
ignore file, then it will be searched even if this flag isn't provided.
This flag can be disabled with --no-hidden.
-");
+"
+ );
let arg = RGArg::switch("hidden")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-hidden");
args.push(arg);
- let arg = RGArg::switch("no-hidden")
- .hidden()
- .overrides("hidden");
+ let arg = RGArg::switch("no-hidden").hidden().overrides("hidden");
args.push(arg);
}
fn flag_iglob(args: &mut Vec<RGArg>) {
- const SHORT: &str =
- "Include or exclude files case insensitively.";
- const LONG: &str = long!("\
+ const SHORT: &str = "Include or exclude files case insensitively.";
+ const LONG: &str = long!(
+ "\
Include or exclude files and directories for searching that match the given
glob. This always overrides any other ignore logic. Multiple glob flags may be
used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
it. Globs are matched case insensitively.
-");
+"
+ );
let arg = RGArg::flag("iglob", "GLOB")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.multiple()
.allow_leading_hyphen();
args.push(arg);
@@ -1323,15 +1418,19 @@ it. Globs are matched case insensitively.
fn flag_ignore_case(args: &mut Vec<RGArg>) {
const SHORT: &str = "Case insensitive search.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When this flag is provided, the given patterns will be searched case
insensitively. The case insensitivity rules used by ripgrep conform to
Unicode's \"simple\" case folding rules.
This flag overrides -s/--case-sensitive and -S/--smart-case.
-");
- let arg = RGArg::switch("ignore-case").short("i")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("ignore-case")
+ .short("i")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("case-sensitive")
.overrides("smart-case");
args.push(arg);
@@ -1339,7 +1438,8 @@ This flag overrides -s/--case-sensitive and -S/--smart-case.
fn flag_ignore_file(args: &mut Vec<RGArg>) {
const SHORT: &str = "Specify additional ignore files.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Specifies a path to one or more .gitignore format rules files. These patterns
are applied after the patterns found in .gitignore and .ignore are applied
and are matched relative to the current working directory. Multiple additional
@@ -1349,9 +1449,11 @@ than later files.
If you are looking for a way to include or exclude files and directories
directly on the command line, then used -g instead.
-");
+"
+ );
let arg = RGArg::flag("ignore-file", "PATH")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.multiple()
.allow_leading_hyphen();
args.push(arg);
@@ -1359,15 +1461,18 @@ directly on the command line, then used -g instead.
fn flag_ignore_file_case_insensitive(args: &mut Vec<RGArg>) {
const SHORT: &str = "Process ignore files case insensitively.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Process ignore files (.gitignore, .ignore, etc.) case insensitively. Note that
this comes with a performance penalty and is most useful on case insensitive
file systems (such as Windows).
This flag can be disabled with the --no-ignore-file-case-insensitive flag.
-");
+"
+ );
let arg = RGArg::switch("ignore-file-case-insensitive")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-ignore-file-case-insensitive");
args.push(arg);
@@ -1379,28 +1484,33 @@ This flag can be disabled with the --no-ignore-file-case-insensitive flag.
fn flag_include_zero(args: &mut Vec<RGArg>) {
const SHORT: &str = "Include files with zero matches in summary";
- const LONG: &str = long!("\
+ 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!("\
+ const LONG: &str = long!(
+ "\
Invert matching. Show lines that do not match the given patterns.
-");
- let arg = RGArg::switch("invert-match").short("v")
- .help(SHORT).long_help(LONG);
+"
+ );
+ let arg =
+ RGArg::switch("invert-match").short("v").help(SHORT).long_help(LONG);
args.push(arg);
}
fn flag_json(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show search results in a JSON Lines format.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Enable printing results in a JSON Lines format.
When this flag is provided, ripgrep will emit a sequence of messages, each
@@ -1442,25 +1552,29 @@ A more complete description of the JSON format used can be found here:
https://docs.rs/grep-printer/*/grep_printer/struct.JSON.html
The JSON Lines format can be disabled with --no-json.
-");
+"
+ );
let arg = RGArg::switch("json")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-json")
.conflicts(&[
- "count", "count-matches",
- "files", "files-with-matches", "files-without-match",
+ "count",
+ "count-matches",
+ "files",
+ "files-with-matches",
+ "files-without-match",
]);
args.push(arg);
- let arg = RGArg::switch("no-json")
- .hidden()
- .overrides("json");
+ let arg = RGArg::switch("no-json").hidden().overrides("json");
args.push(arg);
}
fn flag_line_buffered(args: &mut Vec<RGArg>) {
const SHORT: &str = "Force line buffering.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
When enabled, ripgrep will use line buffering. That is, whenever a matching
line is found, it will be flushed to stdout immediately. This is the default
when ripgrep's stdout is connected to a terminal, but otherwise, ripgrep will
@@ -1473,9 +1587,11 @@ Forceful line buffering can be disabled with --no-line-buffered. Note that
using --no-line-buffered causes ripgrep to revert to its default behavior of
automatically detecting the buffering strategy. To force block buffering, use
the --block-buffered flag.
-");
+"
+ );
let arg = RGArg::switch("line-buffered")
- .help(SHORT).long_help(LONG)
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-line-buffered")
.overrides("block-buffered")
.overrides("no-block-buffered");
@@ -1491,58 +1607,75 @@ the --block-buffered flag.
fn flag_line_number(args: &mut Vec<RGArg>) {
const SHORT: &str = "Show line numbers.";
- const LONG: &str = long!("\
+ const LONG: &str = long!(
+ "\
Show line numbers (1-based). This is enabled by default when searching in a
terminal.
-");
- let arg = RGArg::switch("line-number").short("n")
- .help(SHORT).long_help(LONG)
+"
+ );
+ let arg = RGArg::switch("line-number")
+ .short("n")
+ .help(SHORT)
+ .long_help(LONG)
.overrides("no-line-number");
args.push(arg);
const NO_SHORT: &str = "Suppress line numbers.";
- const NO_LONG: &str = long!("\
+ const NO_LONG: &str = long!(
+ "\
Suppress line numbers. This is enabled by default when not searching in a
terminal.
-");
- let arg = RGArg::switch("no-line-number").short("N")
- .help(NO_SHORT).long_help(NO_LONG)
+"
+ );
+ let arg = RGArg::switch("no-line-number")
+ .short("N")
+ .help(NO_SHORT)
+ .long_help(NO_LONG)
.overrides("line-number");
args.push(arg);
}
fn flag_line_regexp(args: &mut Vec<RGArg>) {
const SHORT: &str = "Only show matches surrounded by line bou