mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-14 22:15:13 +02:00
cli: add --no-ignore-files flag
The purpose of this flag is to force ripgrep to ignore all --ignore-file flags (whether they come before or after --no-ignore-files). This flag can be overridden with --ignore-files. Fixes #1466
This commit is contained in:
@ -614,6 +614,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
|
||||
flag_no_ignore(&mut args);
|
||||
flag_no_ignore_dot(&mut args);
|
||||
flag_no_ignore_exclude(&mut args);
|
||||
flag_no_ignore_files(&mut args);
|
||||
flag_no_ignore_global(&mut args);
|
||||
flag_no_ignore_messages(&mut args);
|
||||
flag_no_ignore_parent(&mut args);
|
||||
@ -1955,7 +1956,11 @@ fn flag_no_ignore(args: &mut Vec<RGArg>) {
|
||||
const LONG: &str = long!(
|
||||
"\
|
||||
Don't respect ignore files (.gitignore, .ignore, etc.). This implies
|
||||
--no-ignore-parent, --no-ignore-dot and --no-ignore-vcs.
|
||||
--no-ignore-dot, --no-ignore-exclude, --no-ignore-global, no-ignore-parent and
|
||||
--no-ignore-vcs.
|
||||
|
||||
This does *not* imply --no-ignore-files, since --ignore-file is specified
|
||||
explicitly as a command line argument.
|
||||
|
||||
This flag can be disabled with the --ignore flag.
|
||||
"
|
||||
@ -2011,6 +2016,27 @@ This flag can be disabled with the --ignore-exclude flag.
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_no_ignore_files(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "Don't respect --ignore-file arguments.";
|
||||
const LONG: &str = long!(
|
||||
"\
|
||||
When set, any --ignore-file flags, even ones that come after this flag, are
|
||||
ignored.
|
||||
|
||||
This flag can be disabled with the --ignore-files flag.
|
||||
"
|
||||
);
|
||||
let arg = RGArg::switch("no-ignore-files")
|
||||
.help(SHORT)
|
||||
.long_help(LONG)
|
||||
.overrides("ignore-files");
|
||||
args.push(arg);
|
||||
|
||||
let arg =
|
||||
RGArg::switch("ignore-files").hidden().overrides("no-ignore-files");
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_no_ignore_global(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "Don't respect global ignore files.";
|
||||
const LONG: &str = long!(
|
||||
|
@ -862,9 +862,11 @@ impl ArgMatches {
|
||||
for path in &paths[1..] {
|
||||
builder.add(path);
|
||||
}
|
||||
for path in self.ignore_paths() {
|
||||
if let Some(err) = builder.add_ignore(path) {
|
||||
ignore_message!("{}", err);
|
||||
if !self.no_ignore_files() {
|
||||
for path in self.ignore_paths() {
|
||||
if let Some(err) = builder.add_ignore(path) {
|
||||
ignore_message!("{}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
builder
|
||||
@ -1228,6 +1230,14 @@ impl ArgMatches {
|
||||
self.is_present("no-ignore-exclude") || self.no_ignore()
|
||||
}
|
||||
|
||||
/// Returns true if explicitly given ignore files should be ignored.
|
||||
fn no_ignore_files(&self) -> bool {
|
||||
// We don't look at no-ignore here because --no-ignore is explicitly
|
||||
// documented to not override --ignore-file. We could change this, but
|
||||
// it would be a fairly severe breaking change.
|
||||
self.is_present("no-ignore-files")
|
||||
}
|
||||
|
||||
/// Returns true if global ignore files should be ignored.
|
||||
fn no_ignore_global(&self) -> bool {
|
||||
self.is_present("no-ignore-global") || self.no_ignore()
|
||||
|
Reference in New Issue
Block a user