diff --git a/src/cli/args.rs b/src/cli/args.rs index 72169627..e6fd66df 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 = 'c', 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/commands/mod.rs b/src/commands/mod.rs index 97410d74..0bcb9b33 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -53,6 +53,13 @@ pub fn run( question_policy: QuestionPolicy, file_visibility_policy: FileVisibilityPolicy, ) -> crate::Result<()> { + if let Some(threads) = args.threads { + rayon::ThreadPoolBuilder::new() + .num_threads(threads) + .build_global() + .unwrap(); + } + match args.cmd { Subcommand::Compress { files, diff --git a/src/utils/logger.rs b/src/utils/logger.rs index 5156308e..0de2dfda 100644 --- a/src/utils/logger.rs +++ b/src/utils/logger.rs @@ -1,4 +1,7 @@ -use std::sync::{mpsc, Arc, Barrier, OnceLock}; +use std::{ + sync::{mpsc, Arc, Barrier, OnceLock}, + thread, +}; pub use logger_thread::spawn_logger_thread; @@ -168,7 +171,7 @@ mod logger_thread { pub fn spawn_logger_thread() { let log_receiver = setup_channel(); - rayon::spawn(move || run_logger(log_receiver)); + thread::spawn(move || run_logger(log_receiver)); } fn run_logger(log_receiver: LogReceiver) { diff --git a/tests/snapshots/ui__ui_test_usage_help_flag-2.snap b/tests/snapshots/ui__ui_test_usage_help_flag-2.snap index cb937d79..058d54ed 100644 --- a/tests/snapshots/ui__ui_test_usage_help_flag-2.snap +++ b/tests/snapshots/ui__ui_test_usage_help_flag-2.snap @@ -1,6 +1,7 @@ --- source: tests/ui.rs expression: "output_to_string(ouch!(\"-h\"))" +snapshot_kind: text --- A command-line utility for easily compressing and decompressing files and directories. @@ -21,5 +22,6 @@ Options: -g, --gitignore Ignores files matched by git's ignore files -f, --format Specify the format of the archive -p, --password decompress or list with password + -c, --threads cocurrent working threads -h, --help Print help (see more with '--help') -V, --version Print version diff --git a/tests/snapshots/ui__ui_test_usage_help_flag.snap b/tests/snapshots/ui__ui_test_usage_help_flag.snap index 921aa8d0..f8a2ad42 100644 --- a/tests/snapshots/ui__ui_test_usage_help_flag.snap +++ b/tests/snapshots/ui__ui_test_usage_help_flag.snap @@ -1,6 +1,7 @@ --- source: tests/ui.rs expression: "output_to_string(ouch!(\"--help\"))" +snapshot_kind: text --- A command-line utility for easily compressing and decompressing files and directories. @@ -43,6 +44,9 @@ Options: -p, --password decompress or list with password + -c, --threads + cocurrent working threads + -h, --help Print help (see a summary with '-h')