refactor: Calculate threading where it is needed

This commit is contained in:
Ed Page 2020-03-23 19:03:15 -05:00 committed by Ed Page
parent 2e1b95fec1
commit b7d412c20e

View file

@ -96,16 +96,6 @@ struct Args {
verbose: clap_verbosity_flag::Verbosity, 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)] #[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")] #[structopt(rename_all = "kebab-case")]
pub struct FileArgs { pub struct FileArgs {
@ -469,7 +459,7 @@ fn check_entry(
} }
fn run() -> Result<i32, anyhow::Error> { fn run() -> Result<i32, anyhow::Error> {
let args = Args::from_args().infer(); let args = Args::from_args();
init_logging(args.verbose.log_level()); init_logging(args.verbose.log_level());
@ -514,6 +504,9 @@ fn run() -> Result<i32, anyhow::Error> {
.check_files(config.default.check_file()) .check_files(config.default.check_file())
.binary(config.files.binary()); .binary(config.files.binary());
let threads = if path.is_file() { 1 } else { args.threads };
let single_threaded = threads == 1;
let mut walk = ignore::WalkBuilder::new(path); let mut walk = ignore::WalkBuilder::new(path);
walk.threads(args.threads) walk.threads(args.threads)
.hidden(config.files.ignore_hidden()) .hidden(config.files.ignore_hidden())
@ -525,8 +518,6 @@ fn run() -> Result<i32, anyhow::Error> {
let reporter = args.format.reporter(); let reporter = args.format.reporter();
let single_threaded = args.threads == 1;
if args.files { if args.files {
if single_threaded { if single_threaded {
for entry in walk.build() { for entry in walk.build() {