Skip to content

Commit

Permalink
feat: add concurrent working threads option to CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys3 committed Nov 30, 2024
1 parent 8c32d2c commit 221084b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,6 +142,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()],
Expand Down
7 changes: 7 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 221084b

Please sign in to comment.