From d1e027e00c94160b36c45d3e76c794cfbbdeb7e6 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 9 Jul 2024 15:42:33 -0400 Subject: [PATCH] control thread pool size, api tweak, typo --- src/args.rs | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/args.rs b/src/args.rs index fa1955b..c8d859b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -99,7 +99,7 @@ pub struct Args { #[arg( short='X', long, help = "exclude from search and printing", - long_help = "exclude from search and printin. accepts glob syntax. separate rules by comma", + long_help = "exclude from search and printing. accepts glob syntax. separate rules by comma", value_parser = parse_glob, value_delimiter = ',', action = ArgAction::Append, @@ -115,6 +115,14 @@ pub struct Args { )] show_hidden: bool, + #[arg( + short='j', long, + help="control size of thread pool", + long_help="set the number of threads in the thread pool. Using zero uses the default number of threads, equal to RAYON_NUM_THREADS if set, or the number of logical CPUs otherwise", + default_value_t = 0, + )] + threads: usize, + #[arg( value_parser = validate_path, help = "items to summate", @@ -127,24 +135,22 @@ impl Args { /// utility method to chuck default values on the end. /// it feels like I should be able to do this with /// clever `clap` macros but I don't know how - pub fn parse_and_process() -> Self { - let mut this = Self::parse(); - - if this.base_two { - this.unit = Unit::Kibi; - } else if this.si { - this.unit = Unit::Kilo; + pub fn post_process(mut self) -> Self { + if self.base_two { + self.unit = Unit::Kibi; + } else if self.si { + self.unit = Unit::Kilo; } - if this.show_hidden { - this.exclude_print = Vec::new(); + if self.show_hidden { + self.exclude_print.clear(); } - if this.path.is_empty() { - this.path = vec![ ".".to_owned() ]; + if self.path.is_empty() { + self.path = vec![ ".".to_owned() ]; } - this + self } pub fn should_exclude(&self, path: &Path, file: &Metadata) -> bool { @@ -186,12 +192,16 @@ impl Args { self.unit } - pub fn iter(&self) -> Iter<'_, String> { - self.path.iter() + pub const fn quiet(&self) -> bool { + self.quiet + } + + pub const fn threads(&self) -> usize { + self.threads } - pub fn quiet(&self) -> bool { - self.quiet + pub fn paths(&self) -> Iter<'_, String> { + self.path.iter() } }