control thread pool size, api tweak, typo

main
nick 2024-07-09 15:42:33 -04:00
parent 848455d0a4
commit d1e027e00c
1 changed files with 27 additions and 17 deletions

View File

@ -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()
}
}