feat(cli): add --threads 1 option for rayon to use only 1 threads

This commit is contained in:
Boshen 2023-04-10 22:13:41 +08:00
parent 48736e53af
commit 04592b3e4f
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
2 changed files with 12 additions and 1 deletions

View file

@ -3,7 +3,7 @@ mod lint;
mod result;
mod walk;
use clap::Command;
use clap::{Arg, Command};
use crate::lint::lint_command;
pub use crate::{
@ -22,4 +22,10 @@ pub fn command() -> Command {
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(lint_command())
.arg(
Arg::new("threads")
.long("threads")
.value_parser(clap::value_parser!(usize))
.help("Number of threads to use. Set to 1 for using only 1 CPU core."),
)
}

View file

@ -12,6 +12,11 @@ use oxc_cli::{command, CliRunResult, LintOptions, LintRunner};
fn main() -> CliRunResult {
let matches = command().get_matches();
if let Some(threads) = matches.get_one::<usize>("threads") {
rayon::ThreadPoolBuilder::new().num_threads(*threads).build_global().unwrap();
}
let Some((subcommand, matches)) = matches.subcommand() else {
return CliRunResult::None
};