From 6b38e1dd4650ac71e9454d82dbefa130c0884cf2 Mon Sep 17 00:00:00 2001 From: ttyS3 Date: Sat, 30 Nov 2024 17:43:50 +0000 Subject: [PATCH] feat: add concurrent working threads option to CLI args --- src/cli/args.rs | 5 +++++ src/cli/mod.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/cli/args.rs b/src/cli/args.rs index 7216962..2dafe92 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -45,6 +45,10 @@ pub struct CliArgs { #[arg(short = 'p', long = "password", global = true)] pub password: Option, + /// cocurrent working threads + #[arg(short = 't', long, global = true)] + pub threads: Option, + // 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()], diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ce6b5d5..4144e53 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -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; -- 2.11.4.GIT