From 661d0f99478f0d8453dfe44173bdc765d7883b1c Mon Sep 17 00:00:00 2001 From: khai96_ Date: Mon, 28 Jul 2025 14:05:46 +0700 Subject: [PATCH] feat(cli)!: `--threads` must be positive --- exports/completion.elv | 2 +- exports/completion.fish | 2 +- exports/completion.ps1 | 2 +- exports/completion.zsh | 2 +- src/app.rs | 2 +- src/args.rs | 2 +- src/args/threads.rs | 7 +++++-- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/exports/completion.elv b/exports/completion.elv index 24909cf..5ccbef6 100644 --- a/exports/completion.elv +++ b/exports/completion.elv @@ -31,7 +31,7 @@ set edit:completion:arg-completer[pdu] = {|@words| cand --column-width 'Maximum widths of the tree column and width of the bar column' cand -m 'Minimal size proportion required to appear' cand --min-ratio 'Minimal size proportion required to appear' - cand --threads 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a number' + cand --threads 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer' cand --json-input 'Read JSON data from stdin' cand --json-output 'Print JSON data instead of an ASCII chart' cand -H 'Detect and subtract the sizes of hardlinks from their parent directory totals' diff --git a/exports/completion.fish b/exports/completion.fish index b260c23..737714b 100644 --- a/exports/completion.fish +++ b/exports/completion.fish @@ -8,7 +8,7 @@ complete -c pdu -s d -l max-depth -l depth -d 'Maximum depth to display the data complete -c pdu -s w -l total-width -l width -d 'Width of the visualization' -r complete -c pdu -l column-width -d 'Maximum widths of the tree column and width of the bar column' -r complete -c pdu -s m -l min-ratio -d 'Minimal size proportion required to appear' -r -complete -c pdu -l threads -d 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a number' -r +complete -c pdu -l threads -d 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer' -r complete -c pdu -l json-input -d 'Read JSON data from stdin' complete -c pdu -l json-output -d 'Print JSON data instead of an ASCII chart' complete -c pdu -s H -l deduplicate-hardlinks -l detect-links -l dedupe-links -d 'Detect and subtract the sizes of hardlinks from their parent directory totals' diff --git a/exports/completion.ps1 b/exports/completion.ps1 index 091975c..dd2eb4f 100644 --- a/exports/completion.ps1 +++ b/exports/completion.ps1 @@ -34,7 +34,7 @@ Register-ArgumentCompleter -Native -CommandName 'pdu' -ScriptBlock { [CompletionResult]::new('--column-width', '--column-width', [CompletionResultType]::ParameterName, 'Maximum widths of the tree column and width of the bar column') [CompletionResult]::new('-m', '-m', [CompletionResultType]::ParameterName, 'Minimal size proportion required to appear') [CompletionResult]::new('--min-ratio', '--min-ratio', [CompletionResultType]::ParameterName, 'Minimal size proportion required to appear') - [CompletionResult]::new('--threads', '--threads', [CompletionResultType]::ParameterName, 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a number') + [CompletionResult]::new('--threads', '--threads', [CompletionResultType]::ParameterName, 'Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer') [CompletionResult]::new('--json-input', '--json-input', [CompletionResultType]::ParameterName, 'Read JSON data from stdin') [CompletionResult]::new('--json-output', '--json-output', [CompletionResultType]::ParameterName, 'Print JSON data instead of an ASCII chart') [CompletionResult]::new('-H', '-H ', [CompletionResultType]::ParameterName, 'Detect and subtract the sizes of hardlinks from their parent directory totals') diff --git a/exports/completion.zsh b/exports/completion.zsh index 3e655e5..5553935 100644 --- a/exports/completion.zsh +++ b/exports/completion.zsh @@ -36,7 +36,7 @@ block-count\:"Count numbers of blocks"))' \ '*--column-width=[Maximum widths of the tree column and width of the bar column]:TREE_WIDTH:_default:TREE_WIDTH:_default' \ '-m+[Minimal size proportion required to appear]:MIN_RATIO:_default' \ '--min-ratio=[Minimal size proportion required to appear]:MIN_RATIO:_default' \ -'--threads=[Set the maximum number of threads to spawn. Could be either "auto", "max", or a number]:THREADS:_default' \ +'--threads=[Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer]:THREADS:_default' \ '(-q --quantity -H --deduplicate-hardlinks)--json-input[Read JSON data from stdin]' \ '--json-output[Print JSON data instead of an ASCII chart]' \ '-H[Detect and subtract the sizes of hardlinks from their parent directory totals]' \ diff --git a/src/app.rs b/src/app.rs index c8d8905..7fad5b5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -145,7 +145,7 @@ impl App { } } Threads::Max => None, - Threads::Fixed(threads) => Some(threads), + Threads::Fixed(threads) => Some(threads.get()), }; if let Some(threads) = threads { diff --git a/src/args.rs b/src/args.rs index 0fb3001..48fb4c6 100644 --- a/src/args.rs +++ b/src/args.rs @@ -157,7 +157,7 @@ pub struct Args { #[clap(long, short)] pub progress: bool, - /// Set the maximum number of threads to spawn. Could be either "auto", "max", or a number. + /// Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer. #[clap(long, default_value_t = Threads::Auto)] pub threads: Threads, diff --git a/src/args/threads.rs b/src/args/threads.rs index 4b51c92..a97ecec 100644 --- a/src/args/threads.rs +++ b/src/args/threads.rs @@ -1,5 +1,8 @@ use derive_more::{Display, Error}; -use std::{num::ParseIntError, str::FromStr}; +use std::{ + num::{NonZeroUsize, ParseIntError}, + str::FromStr, +}; const AUTO: &str = "auto"; const MAX: &str = "max"; @@ -12,7 +15,7 @@ pub enum Threads { Auto, #[display("{MAX}")] Max, - Fixed(usize), + Fixed(NonZeroUsize), } /// Error that occurs when converting a string to an instance of [`Threads`].