Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3b26ddd
Initial plan
Copilot Feb 28, 2026
b83af13
docs: add CLI usage documentation and sync_help tests
Copilot Feb 28, 2026
d17b9c1
fix: restrict sync_help tests to unix only
Copilot Feb 28, 2026
81b8f0d
feat: parse long.help to generate structured USAGE.md
Copilot Feb 28, 2026
18be173
refactor: parse flags/aliases/examples properly; fix Clippy warnings;…
Copilot Feb 28, 2026
8dce0c9
refactor(usage_md): heading-based options, periods on descriptions, i…
Copilot Feb 28, 2026
b30f626
fix: remove redundant .iter() on Vec in render_option_item
Copilot Feb 28, 2026
991ac44
refactor(usage_md): move render to src/usage_md, use Args::command(),…
Copilot Feb 28, 2026
40f6184
refactor(usage_md): address review comments - iterator return type, C…
Copilot Feb 28, 2026
30c6e42
refactor(usage_md): use strip_prefix consistently for anchor id gener…
Copilot Feb 28, 2026
d92ac00
refactor(usage_md): rewrite render to use clap introspection API
Copilot Feb 28, 2026
9632a78
fix(lib): move pub mod usage_md into the cfg(feature = \"cli\") group
Copilot Feb 28, 2026
c4b5c02
refactor(usage_md): address all review comments and fix CI failures
Copilot Feb 28, 2026
de881ba
docs: remove unnecessary text
KSXGitHub Feb 28, 2026
73077f4
refactor: undo
KSXGitHub Feb 28, 2026
8e17223
docs: remove unnecessary documentation
KSXGitHub Feb 28, 2026
55655c8
style: imports together
KSXGitHub Feb 28, 2026
08a13a3
style: use shadowing
KSXGitHub Feb 28, 2026
94bf09c
refactor: simplify
KSXGitHub Feb 28, 2026
01f0676
refactor: correct a function name
KSXGitHub Feb 28, 2026
d5f4d65
refactor: stop using short variable
KSXGitHub Feb 28, 2026
96062b0
refactor: remove temporary `Vec`
KSXGitHub Feb 28, 2026
055dad0
refactor: remove duplicated `to_string_lossy`
KSXGitHub Feb 28, 2026
8316641
refactor: rename a variable
KSXGitHub Feb 28, 2026
f4d6360
refactor: unabbreviate a variable
KSXGitHub Feb 28, 2026
fc15472
refactor: unabbreviate a variable
KSXGitHub Feb 28, 2026
54fad48
refactor: unabbreviate some variables
KSXGitHub Feb 28, 2026
22236c8
refactor: unabbreviate some variables
KSXGitHub Feb 28, 2026
a6adb98
refactor: unabbreviate a variable
KSXGitHub Feb 28, 2026
c642f25
refactor: unabbreviate a variable
KSXGitHub Feb 28, 2026
2d745ae
refactor(usage_md): extract helper functions, fix var names, use curr…
Copilot Feb 28, 2026
91a452f
refactor: simplify
KSXGitHub Feb 28, 2026
5ecaea3
refactor: shorten some variable names
KSXGitHub Feb 28, 2026
c7895dd
refactor: prefer turbo fish
KSXGitHub Feb 28, 2026
691f321
refactor: remove unnecessary bindings
KSXGitHub Feb 28, 2026
2309236
refactor: stop using temporary `Vec`
KSXGitHub Feb 28, 2026
46b9109
refactor: make `out: &String` the first arg
KSXGitHub Feb 28, 2026
9917068
refactor: remove potential panic
KSXGitHub Feb 28, 2026
8036fdf
refactor: remove unnecessary allocation
KSXGitHub Feb 28, 2026
0fa4aa8
fix(docs/usage): stop concatenating
KSXGitHub Feb 28, 2026
c74bc7f
fix(docs): unnecessary comments
KSXGitHub Feb 28, 2026
5fc9f28
fix: required positional args use angle brackets; use get_action() to…
Copilot Feb 28, 2026
03ec521
refactor: reduce allocation
KSXGitHub Feb 28, 2026
d2b6169
feat(docs): still show default of `"true"`
KSXGitHub Feb 28, 2026
c178b5d
refactor: replace the brittle string replacement
KSXGitHub Feb 28, 2026
32628c6
refactor: remove unused link
KSXGitHub Feb 28, 2026
bf66a60
fix: strip trailing whitespace from help exports and normalize in tests
Copilot Feb 28, 2026
22fd0af
refactor: use `pipe`
KSXGitHub Feb 28, 2026
38b2369
test: remove unnecessary trimming
KSXGitHub Feb 28, 2026
ef37654
refactor: use macro
KSXGitHub Feb 28, 2026
b801758
refactor: rename a test
KSXGitHub Feb 28, 2026
b516907
chore(cargo): include `USAGE.md`
KSXGitHub Feb 28, 2026
05e0285
refactor: split the tests
KSXGitHub Feb 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ name = "pdu-completions"
path = "cli/completions.rs"
required-features = ["cli-completions"]

[[bin]]
name = "pdu-usage-md"
path = "cli/usage_md.rs"
required-features = ["cli"]

[features]
default = ["cli"]
json = ["serde/derive", "serde_json"]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ The benchmark was generated by [a GitHub Workflow](https://github.com/KSXGitHub/
* Do not differentiate filesystem: Mounted folders are counted as normal folders.
* The runtime is optimized at the expense of binary size.

## Usage

See [USAGE.md](./USAGE.md) for the full help text.
Comment thread
KSXGitHub marked this conversation as resolved.

## Development

### Prerequisites
Expand Down
208 changes: 208 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Usage

```sh
pdu [OPTIONS] [FILES]...
```

## Arguments

* `[FILES]...`: List of files and/or directories.

## Options

<a id="json-input" name="json-input"></a>
### `--json-input`

Read JSON data from stdin.

<a id="json-output" name="json-output"></a>
### `--json-output`

Print JSON data instead of an ASCII chart.

<a id="option-b" name="option-b"></a><a id="bytes-format" name="bytes-format"></a>
### `--bytes-format`

* _Aliases:_ `-b`.
* _Default:_ `metric`.
* _Choices:_
- `plain`: Display plain number of bytes without units
- `metric`: Use metric scale, i.e. 1K = 1000B, 1M = 1000K, and so on
- `binary`: Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on

How to display the numbers of bytes.

<a id="option-H" name="option-H"></a><a id="deduplicate-hardlinks" name="deduplicate-hardlinks"></a><a id="detect-links" name="detect-links"></a><a id="dedupe-links" name="dedupe-links"></a>
### `--deduplicate-hardlinks`
Comment thread
KSXGitHub marked this conversation as resolved.

* _Aliases:_ `-H`, `--detect-links`, `--dedupe-links`.

Detect and subtract the sizes of hardlinks from their parent directory totals.

<a id="top-down" name="top-down"></a>
### `--top-down`

Print the tree top-down instead of bottom-up.

<a id="align-right" name="align-right"></a>
### `--align-right`

Set the root of the bars to the right.

<a id="option-q" name="option-q"></a><a id="quantity" name="quantity"></a>
### `--quantity`

* _Aliases:_ `-q`.
* _Default:_ `block-size`.
* _Choices:_
- `apparent-size`: Measure apparent sizes
- `block-size`: Measure block sizes (block-count * 512B)
- `block-count`: Count numbers of blocks

Aspect of the files/directories to be measured.

<a id="option-d" name="option-d"></a><a id="max-depth" name="max-depth"></a><a id="depth" name="depth"></a>
### `--max-depth`

* _Aliases:_ `-d`, `--depth`.
* _Default:_ `10`.

Maximum depth to display the data. Could be either "inf" or a positive integer.

<a id="option-w" name="option-w"></a><a id="total-width" name="total-width"></a><a id="width" name="width"></a>
### `--total-width`

* _Aliases:_ `-w`, `--width`.

Width of the visualization.

<a id="column-width" name="column-width"></a>
### `--column-width`

Maximum widths of the tree column and width of the bar column.

<a id="option-m" name="option-m"></a><a id="min-ratio" name="min-ratio"></a>
### `--min-ratio`

* _Aliases:_ `-m`.
* _Default:_ `0.01`.

Minimal size proportion required to appear.

<a id="no-sort" name="no-sort"></a>
### `--no-sort`

Do not sort the branches in the tree.

<a id="option-s" name="option-s"></a><a id="silent-errors" name="silent-errors"></a><a id="no-errors" name="no-errors"></a>
### `--silent-errors`

* _Aliases:_ `-s`, `--no-errors`.

Prevent filesystem error messages from appearing in stderr.

<a id="option-p" name="option-p"></a><a id="progress" name="progress"></a>
### `--progress`

* _Aliases:_ `-p`.

Report progress being made at the expense of performance.

<a id="threads" name="threads"></a>
### `--threads`

* _Default:_ `auto`.

Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer.

<a id="omit-json-shared-details" name="omit-json-shared-details"></a>
### `--omit-json-shared-details`

Do not output `.shared.details` in the JSON output.

<a id="omit-json-shared-summary" name="omit-json-shared-summary"></a>
### `--omit-json-shared-summary`

Do not output `.shared.summary` in the JSON output.

<a id="option-h" name="option-h"></a><a id="help" name="help"></a>
### `--help`

* _Aliases:_ `-h`.

Print help.

<a id="option-V" name="option-V"></a><a id="version" name="version"></a>
### `--version`

* _Aliases:_ `-V`.

Print version.

## Examples

### Show disk usage chart of current working directory

```sh
pdu
```

### Show disk usage chart of a single file or directory

```sh
pdu path/to/file/or/directory
```

### Compare disk usages of multiple files and/or directories

```sh
pdu file.txt dir/
```

### Show chart in apparent sizes instead of block sizes

```sh
pdu --quantity=apparent-size
```

### Detect and subtract the sizes of hardlinks from their parent nodes

```sh
pdu --deduplicate-hardlinks
```

### Show sizes in plain numbers instead of metric units

```sh
pdu --bytes-format=plain
```

### Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)

```sh
pdu --bytes-format=binary
```

### Show disk usage chart of all entries regardless of size

```sh
pdu --min-ratio=0
```

### Only show disk usage chart of entries whose size is at least 5% of total

```sh
pdu --min-ratio=0.05
```

### Show disk usage data as JSON instead of chart

```sh
pdu --min-ratio=0 --max-depth=inf --json-output | jq
```

### Visualize existing JSON representation of disk usage data

```sh
pdu --json-input < disk-usage.json
```
5 changes: 5 additions & 0 deletions cli/usage_md.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use parallel_disk_usage::usage_md::render_usage_md;

fn main() {
println!("{}", render_usage_md().trim_end());
}
129 changes: 129 additions & 0 deletions exports/long.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Summarize disk usage of the set of files, recursively for directories.

Copyright: Apache-2.0 © 2021 Hoàng Văn Khải <https://github.com/KSXGitHub/>
Sponsor: https://github.com/sponsors/KSXGitHub

Usage: pdu [OPTIONS] [FILES]...

Arguments:
[FILES]...
List of files and/or directories

Options:
--json-input
Read JSON data from stdin

--json-output
Print JSON data instead of an ASCII chart

-b, --bytes-format <BYTES_FORMAT>
How to display the numbers of bytes

Possible values:
- plain: Display plain number of bytes without units
- metric: Use metric scale, i.e. 1K = 1000B, 1M = 1000K, and so on
- binary: Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on

[default: metric]

-H, --deduplicate-hardlinks
Detect and subtract the sizes of hardlinks from their parent directory totals

[aliases: --detect-links, --dedupe-links]
Comment thread
KSXGitHub marked this conversation as resolved.

--top-down
Print the tree top-down instead of bottom-up

--align-right
Set the root of the bars to the right

-q, --quantity <QUANTITY>
Aspect of the files/directories to be measured

Possible values:
- apparent-size: Measure apparent sizes
- block-size: Measure block sizes (block-count * 512B)
- block-count: Count numbers of blocks

[default: block-size]

-d, --max-depth <MAX_DEPTH>
Maximum depth to display the data. Could be either "inf" or a positive integer

[default: 10]
[aliases: --depth]

-w, --total-width <TOTAL_WIDTH>
Width of the visualization

[aliases: --width]

--column-width <TREE_WIDTH> <BAR_WIDTH>
Maximum widths of the tree column and width of the bar column

-m, --min-ratio <MIN_RATIO>
Minimal size proportion required to appear

[default: 0.01]

--no-sort
Do not sort the branches in the tree

-s, --silent-errors
Prevent filesystem error messages from appearing in stderr

[aliases: --no-errors]

-p, --progress
Report progress being made at the expense of performance

--threads <THREADS>
Set the maximum number of threads to spawn. Could be either "auto", "max", or a positive integer

[default: auto]

--omit-json-shared-details
Do not output `.shared.details` in the JSON output

--omit-json-shared-summary
Do not output `.shared.summary` in the JSON output

-h, --help
Print help (see a summary with '-h')

-V, --version
Print version

Examples:
Show disk usage chart of current working directory
$ pdu

Show disk usage chart of a single file or directory
$ pdu path/to/file/or/directory

Compare disk usages of multiple files and/or directories
$ pdu file.txt dir/

Show chart in apparent sizes instead of block sizes
$ pdu --quantity=apparent-size

Detect and subtract the sizes of hardlinks from their parent nodes
$ pdu --deduplicate-hardlinks

Show sizes in plain numbers instead of metric units
$ pdu --bytes-format=plain

Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)
$ pdu --bytes-format=binary

Show disk usage chart of all entries regardless of size
$ pdu --min-ratio=0

Only show disk usage chart of entries whose size is at least 5% of total
$ pdu --min-ratio=0.05

Show disk usage data as JSON instead of chart
$ pdu --min-ratio=0 --max-depth=inf --json-output | jq

Visualize existing JSON representation of disk usage data
$ pdu --json-input < disk-usage.json
Loading