From 6bbf8390ff1e4c9d41688c2746ab1070f9e25a4e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 12 Jul 2019 21:39:38 -0600 Subject: [PATCH] feat: Ignore parents flag --- src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3111eaf..a784e4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,6 +76,16 @@ struct Options { raw(hidden = "true") )] ignore_global: bool, + + #[structopt(long, raw(overrides_with = r#""ignore-parent""#))] + /// Don't respect ignore files in parent directories. + no_ignore_parent: bool, + #[structopt( + long, + raw(overrides_with = r#""no-ignore-parent""#), + raw(hidden = "true") + )] + ignore_parent: bool, } impl Options { @@ -116,6 +126,16 @@ impl Options { .or_else(|| self.ignore_files()) } + pub fn ignore_parent(&self) -> Option { + match (self.no_ignore_parent, self.ignore_parent) { + (true, false) => Some(false), + (false, true) => Some(true), + (false, false) => None, + (_, _) => unreachable!("StructOpt should make this impossible"), + } + .or_else(|| self.ignore_files()) + } + fn ignore_files(&self) -> Option { match (self.no_ignore, self.ignore) { (true, false) => Some(false), @@ -142,7 +162,8 @@ fn run() -> Result<(), failure::Error> { walk.threads(options.threads) .hidden(options.ignore_hidden().unwrap_or(true)) .ignore(options.ignore_dot().unwrap_or(true)) - .git_global(options.ignore_global().unwrap_or(true)); + .git_global(options.ignore_global().unwrap_or(true)) + .parents(options.ignore_parent().unwrap_or(true)); // TODO Add build_parallel for options.threads != 1 for entry in walk.build() { let entry = entry?;