From 1a06f0cab2d95d5e1f1f809e7f96289486d6ccaf Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 10 Dec 2021 21:00:33 +0100 Subject: [PATCH] main: add option -h to skip hidden files by default --- src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9961a5b..fb6b36b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,12 @@ fn main() { .long("edit") .help("Remove unused code and write to source file"), ) + .arg( + clap::Arg::with_name("HIDDEN") + .short("h") + .long("hidden") + .help("Recurse into hidden subdirectories and process hidden .*.nix files"), + ) .arg( clap::Arg::with_name("FILE_PATHS") .multiple(true) @@ -51,6 +57,14 @@ fn main() { }; let quiet = matches.is_present("QUIET"); let edit = matches.is_present("EDIT"); + let is_visible = if matches.is_present("HIDDEN") { + |_: &walkdir::DirEntry| true + } else { + |entry: &walkdir::DirEntry| entry.file_name() + .to_str() + .map(|s| s == "." || ! s.starts_with(".")) + .unwrap_or(false) + }; let file_paths = matches.values_of("FILE_PATHS").expect("FILE_PATHS"); let files = file_paths.flat_map(|path| { @@ -58,6 +72,8 @@ fn main() { let files: Box> = if meta.is_dir() { Box::new( walkdir::WalkDir::new(path) + .into_iter() + .filter_entry(is_visible) .into_iter() .map(|result| result.unwrap().path().display().to_string()) .filter(|path| {