feat: add concurrent working threads option to CLI args

This commit is contained in:
ttyS3 2024-11-30 17:43:50 +00:00 committed by João Marcos
parent 195483a182
commit 6b38e1dd46
2 changed files with 12 additions and 0 deletions

View File

@ -45,6 +45,10 @@ pub struct CliArgs {
#[arg(short = 'p', long = "password", global = true)]
pub password: Option<OsString>,
/// cocurrent working threads
#[arg(short = 't', long, global = true)]
pub threads: Option<usize>,
// Ouch and claps subcommands
#[command(subcommand)]
pub cmd: Subcommand,
@ -142,6 +146,7 @@ mod tests {
format: None,
// This is usually replaced in assertion tests
password: None,
threads: None,
cmd: Subcommand::Decompress {
// Put a crazy value here so no test can assert it unintentionally
files: vec!["\x00\x11\x22".into()],

View File

@ -28,6 +28,13 @@ impl CliArgs {
set_accessible(args.accessible);
if let Some(threads) = args.threads {
rayon::ThreadPoolBuilder::new()
.num_threads(threads)
.build_global()
.unwrap();
}
let (Subcommand::Compress { files, .. }
| Subcommand::Decompress { files, .. }
| Subcommand::List { archives: files, .. }) = &mut args.cmd;