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())