Skip to content

Commit c94ee09

Browse files
committed
chore(git): merge from master
2 parents 84c93d4 + 737cf89 commit c94ee09

File tree

8 files changed

+74
-19
lines changed

8 files changed

+74
-19
lines changed

exports/completion.elv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ set edit:completion:arg-completer[pdu] = {|@words|
2222
cand --bytes-format 'How to display the numbers of bytes'
2323
cand -q 'Aspect of the files/directories to be measured'
2424
cand --quantity 'Aspect of the files/directories to be measured'
25-
cand -d 'Maximum depth to display the data (must be greater than 0)'
26-
cand --max-depth 'Maximum depth to display the data (must be greater than 0)'
27-
cand --depth 'Maximum depth to display the data (must be greater than 0)'
25+
cand -d 'Maximum depth to display the data. Could be either "inf" or a positive integer'
26+
cand --max-depth 'Maximum depth to display the data. Could be either "inf" or a positive integer'
27+
cand --depth 'Maximum depth to display the data. Could be either "inf" or a positive integer'
2828
cand -w 'Width of the visualization'
2929
cand --total-width 'Width of the visualization'
3030
cand --width 'Width of the visualization'

exports/completion.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ binary\t'Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on'"
44
complete -c pdu -s q -l quantity -d 'Aspect of the files/directories to be measured' -r -f -a "apparent-size\t'Measure apparent sizes'
55
block-size\t'Measure block sizes (block-count * 512B)'
66
block-count\t'Count numbers of blocks'"
7-
complete -c pdu -s d -l max-depth -l depth -d 'Maximum depth to display the data (must be greater than 0)' -r
7+
complete -c pdu -s d -l max-depth -l depth -d 'Maximum depth to display the data. Could be either "inf" or a positive integer' -r
88
complete -c pdu -s w -l total-width -l width -d 'Width of the visualization' -r
99
complete -c pdu -l column-width -d 'Maximum widths of the tree column and width of the bar column' -r
1010
complete -c pdu -s m -l min-ratio -d 'Minimal size proportion required to appear' -r

exports/completion.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Register-ArgumentCompleter -Native -CommandName 'pdu' -ScriptBlock {
2525
[CompletionResult]::new('--bytes-format', '--bytes-format', [CompletionResultType]::ParameterName, 'How to display the numbers of bytes')
2626
[CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Aspect of the files/directories to be measured')
2727
[CompletionResult]::new('--quantity', '--quantity', [CompletionResultType]::ParameterName, 'Aspect of the files/directories to be measured')
28-
[CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Maximum depth to display the data (must be greater than 0)')
29-
[CompletionResult]::new('--max-depth', '--max-depth', [CompletionResultType]::ParameterName, 'Maximum depth to display the data (must be greater than 0)')
30-
[CompletionResult]::new('--depth', '--depth', [CompletionResultType]::ParameterName, 'Maximum depth to display the data (must be greater than 0)')
28+
[CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Maximum depth to display the data. Could be either "inf" or a positive integer')
29+
[CompletionResult]::new('--max-depth', '--max-depth', [CompletionResultType]::ParameterName, 'Maximum depth to display the data. Could be either "inf" or a positive integer')
30+
[CompletionResult]::new('--depth', '--depth', [CompletionResultType]::ParameterName, 'Maximum depth to display the data. Could be either "inf" or a positive integer')
3131
[CompletionResult]::new('-w', '-w', [CompletionResultType]::ParameterName, 'Width of the visualization')
3232
[CompletionResult]::new('--total-width', '--total-width', [CompletionResultType]::ParameterName, 'Width of the visualization')
3333
[CompletionResult]::new('--width', '--width', [CompletionResultType]::ParameterName, 'Width of the visualization')

exports/completion.zsh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ block-count\:"Count numbers of blocks"))' \
2727
'--quantity=[Aspect of the files/directories to be measured]:QUANTITY:((apparent-size\:"Measure apparent sizes"
2828
block-size\:"Measure block sizes (block-count * 512B)"
2929
block-count\:"Count numbers of blocks"))' \
30-
'-d+[Maximum depth to display the data (must be greater than 0)]:MAX_DEPTH:_default' \
31-
'--max-depth=[Maximum depth to display the data (must be greater than 0)]:MAX_DEPTH:_default' \
32-
'--depth=[Maximum depth to display the data (must be greater than 0)]:MAX_DEPTH:_default' \
30+
'-d+[Maximum depth to display the data. Could be either "inf" or a positive integer]:MAX_DEPTH:_default' \
31+
'--max-depth=[Maximum depth to display the data. Could be either "inf" or a positive integer]:MAX_DEPTH:_default' \
32+
'--depth=[Maximum depth to display the data. Could be either "inf" or a positive integer]:MAX_DEPTH:_default' \
3333
'(--column-width)-w+[Width of the visualization]:TOTAL_WIDTH:_default' \
3434
'(--column-width)--total-width=[Width of the visualization]:TOTAL_WIDTH:_default' \
3535
'(--column-width)--width=[Width of the visualization]:TOTAL_WIDTH:_default' \

src/app/sub.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
args::Fraction,
2+
args::{Depth, Fraction},
33
data_tree::DataTree,
44
fs_tree_builder::FsTreeBuilder,
55
get_size::GetSize,
@@ -14,7 +14,7 @@ use crate::{
1414
};
1515
use pipe_trait::Pipe;
1616
use serde::Serialize;
17-
use std::{io::stdout, iter::once, num::NonZeroU64, path::PathBuf};
17+
use std::{io::stdout, iter::once, path::PathBuf};
1818

1919
/// The sub program of the main application.
2020
pub struct Sub<Size, SizeGetter, HardlinksHandler, Report>
@@ -38,7 +38,7 @@ where
3838
/// Distribution and number of characters/blocks can be placed in a line.
3939
pub column_width_distribution: ColumnWidthDistribution,
4040
/// Maximum number of levels that should be visualized.
41-
pub max_depth: NonZeroU64,
41+
pub max_depth: Depth,
4242
/// [Get the size](GetSize) of files/directories.
4343
pub size_getter: SizeGetter,
4444
/// Handle to detect, record, and deduplicate hardlinks.

src/args.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
pub mod depth;
12
pub mod fraction;
23
pub mod quantity;
34
pub mod threads;
45

6+
pub use depth::Depth;
57
pub use fraction::Fraction;
68
pub use quantity::Quantity;
79
pub use threads::Threads;
@@ -10,7 +12,7 @@ use crate::{bytes_format::BytesFormat, visualizer::ColumnWidthDistribution};
1012
use clap::{ColorChoice, Parser};
1113
use derive_setters::Setters;
1214
use smart_default::SmartDefault;
13-
use std::{num::NonZeroU64, path::PathBuf};
15+
use std::path::PathBuf;
1416
use terminal_size::{terminal_size, Width};
1517
use text_block_macros::text_block;
1618

@@ -41,7 +43,7 @@ use text_block_macros::text_block;
4143
" $ pdu --bytes-format=binary"
4244
" $ pdu --min-ratio=0"
4345
" $ pdu --min-ratio=0.05"
44-
" $ pdu --min-ratio=0 --json-output | jq"
46+
" $ pdu --min-ratio=0 --max-depth=inf --json-output | jq"
4547
" $ pdu --json-input < disk-usage.json"
4648
},
4749
@@ -75,7 +77,7 @@ use text_block_macros::text_block;
7577
" $ pdu --min-ratio=0.05"
7678
""
7779
" Show disk usage data as JSON instead of chart"
78-
" $ pdu --min-ratio=0 --json-output | jq"
80+
" $ pdu --min-ratio=0 --max-depth=inf --json-output | jq"
7981
""
8082
" Visualize existing JSON representation of disk usage data"
8183
" $ pdu --json-input < disk-usage.json"
@@ -123,10 +125,10 @@ pub struct Args {
123125
#[default(Quantity::DEFAULT)]
124126
pub quantity: Quantity,
125127

126-
/// Maximum depth to display the data (must be greater than 0).
128+
/// Maximum depth to display the data. Could be either "inf" or a positive integer.
127129
#[clap(long, short = 'd', default_value = "10", visible_alias = "depth")]
128130
#[default(_code = "10.try_into().unwrap()")]
129-
pub max_depth: NonZeroU64,
131+
pub max_depth: Depth,
130132

131133
/// Width of the visualization.
132134
#[clap(

src/args/depth.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use derive_more::{Display, Error};
2+
use std::{
3+
num::{NonZeroU64, ParseIntError, TryFromIntError},
4+
str::FromStr,
5+
};
6+
7+
const INFINITE: &str = "inf";
8+
9+
/// Maximum depth of the tree.
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
11+
pub enum Depth {
12+
#[display("{INFINITE}")]
13+
Infinite,
14+
Finite(NonZeroU64),
15+
}
16+
17+
impl Depth {
18+
/// Convert depth into something comparable.
19+
pub(crate) fn get(self) -> u64 {
20+
match self {
21+
Depth::Infinite => u64::MAX,
22+
Depth::Finite(value) => value.get(),
23+
}
24+
}
25+
}
26+
27+
/// Error that occurs when parsing a string as [`Depth`].
28+
#[derive(Debug, Display, Clone, PartialEq, Eq, Error)]
29+
#[non_exhaustive]
30+
pub enum FromStrError {
31+
#[display("Value is neither {INFINITE:?} nor a positive integer: {_0}")]
32+
InvalidSyntax(ParseIntError),
33+
}
34+
35+
impl FromStr for Depth {
36+
type Err = FromStrError;
37+
fn from_str(text: &str) -> Result<Self, Self::Err> {
38+
let text = text.trim();
39+
if text == INFINITE {
40+
return Ok(Depth::Infinite);
41+
}
42+
text.parse()
43+
.map_err(FromStrError::InvalidSyntax)
44+
.map(Depth::Finite)
45+
}
46+
}
47+
48+
impl TryFrom<u64> for Depth {
49+
type Error = TryFromIntError;
50+
fn try_from(value: u64) -> Result<Self, Self::Error> {
51+
value.try_into().map(Depth::Finite)
52+
}
53+
}

tests/cli_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn max_depth_0() {
9797
assert_eq!(
9898
stderr,
9999
text_block! {
100-
"error: invalid value '0' for '--max-depth <MAX_DEPTH>': number would be zero for non-zero type"
100+
r#"error: invalid value '0' for '--max-depth <MAX_DEPTH>': Value is neither "inf" nor a positive integer: number would be zero for non-zero type"#
101101
""
102102
"For more information, try '--help'."
103103
}

0 commit comments

Comments
 (0)