From 333762f55cdc64af3bedeb842c2d70f09eff7971 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 25 Oct 2019 16:34:21 -0600 Subject: [PATCH] refactor: Prepare for threads --- src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 540f44c..1224e58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,6 +79,10 @@ struct Args { )] pub format: Format, + #[structopt(short = "j", long = "threads", default_value = "0")] + /// The approximate number of threads to use. + threads: usize, + #[structopt(flatten)] config: ConfigArgs, @@ -86,6 +90,16 @@ struct Args { verbose: clap_verbosity_flag::Verbosity, } +impl Args { + pub fn infer(mut self) -> Self { + if self.path.len() == 1 && self.path[0].is_file() { + self.threads = 1; + } + + self + } +} + #[derive(Debug, StructOpt)] #[structopt(rename_all = "kebab-case")] pub struct FileArgs { @@ -421,7 +435,7 @@ fn check_entry( } fn run() -> Result { - let args = Args::from_args(); + let args = Args::from_args().infer(); init_logging(args.verbose.log_level()); @@ -468,7 +482,8 @@ fn run() -> Result { .binary(config.files.binary()); let mut walk = ignore::WalkBuilder::new(path); - walk.hidden(config.files.ignore_hidden()) + walk.threads(args.threads) + .hidden(config.files.ignore_hidden()) .ignore(config.files.ignore_dot()) .git_global(config.files.ignore_global()) .git_ignore(config.files.ignore_vcs())