Skip to content

Commit ed7181b

Browse files
committed
refactor(man): replace clap_mangen with custom roff implementation
Drop the clap_mangen dependency and write a custom man page renderer that produces proper roff output. This fixes several formatting issues: - DESCRIPTION section now uses .PP for paragraph breaks (copyright and sponsor lines no longer merge) - EXAMPLES section uses .TP for description/command pairs with .nf/.fi for literal command rendering - Boolean flags no longer show redundant "Possible values: true, false" - Visible aliases are included in option headers https://claude.ai/code/session_01CrXuWDMVQsiUBoy6ceACsF
1 parent 1fa57cc commit ed7181b

6 files changed

Lines changed: 332 additions & 103 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ default = ["cli"]
6464
json = ["serde/derive", "serde_json"]
6565
cli = ["clap/derive", "clap_complete", "clap-utilities", "json"]
6666
cli-completions = ["cli"]
67-
cli-man = ["cli", "clap_mangen"]
67+
cli-man = ["cli"]
6868
ai-instructions = ["clap/derive"]
6969

7070
[dependencies]
7171
assert-cmp = "0.3.0"
7272
clap = { version = "4.5.60", optional = true }
7373
clap_complete = { version = "4.5.66", optional = true }
74-
clap_mangen = { version = "0.2.27", optional = true }
7574
clap-utilities = { version = "0.3.0", optional = true }
7675
dashmap = "6.1.0"
7776
derive_more = { version = "2.1.1", features = ["full"] }

cli/man_page.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
use parallel_disk_usage::man_page::render_man_page;
2-
use std::process::ExitCode;
32

4-
fn main() -> ExitCode {
5-
match render_man_page() {
6-
Ok(content) => {
7-
print!("{content}");
8-
ExitCode::SUCCESS
9-
}
10-
Err(error) => {
11-
eprintln!("error: {error}");
12-
ExitCode::FAILURE
13-
}
14-
}
3+
fn main() {
4+
print!("{}", render_man_page());
155
}

exports/pdu.1

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
.ie \n(.g .ds Aq \(aq
2-
.el .ds Aq '
3-
.TH pdu 1 "pdu 0.21.1"
1+
.TH pdu 1 "pdu 0.21.1"
42
.SH NAME
53
pdu \- Summarize disk usage of the set of files, recursively for directories.
64
.SH SYNOPSIS
7-
\fBpdu\fR [\fB\-\-json\-input\fR] [\fB\-\-json\-output\fR] [\fB\-b\fR|\fB\-\-bytes\-format\fR] [\fB\-H\fR|\fB\-\-deduplicate\-hardlinks\fR] [\fB\-x\fR|\fB\-\-one\-file\-system\fR] [\fB\-\-top\-down\fR] [\fB\-\-align\-right\fR] [\fB\-q\fR|\fB\-\-quantity\fR] [\fB\-d\fR|\fB\-\-max\-depth\fR] [\fB\-w\fR|\fB\-\-total\-width\fR] [\fB\-\-column\-width\fR] [\fB\-m\fR|\fB\-\-min\-ratio\fR] [\fB\-\-no\-sort\fR] [\fB\-s\fR|\fB\-\-silent\-errors\fR] [\fB\-p\fR|\fB\-\-progress\fR] [\fB\-\-threads\fR] [\fB\-\-omit\-json\-shared\-details\fR] [\fB\-\-omit\-json\-shared\-summary\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIFILES\fR]
5+
\fBpdu\fR [\fB\-\-json\-input\fR] [\fB\-\-json\-output\fR] [\fB\-b\fR|\fB\-\-bytes\-format\fR \fIBYTES_FORMAT\fR] [\fB\-H\fR|\fB\-\-deduplicate\-hardlinks\fR] [\fB\-x\fR|\fB\-\-one\-file\-system\fR] [\fB\-\-top\-down\fR] [\fB\-\-align\-right\fR] [\fB\-q\fR|\fB\-\-quantity\fR \fIQUANTITY\fR] [\fB\-d\fR|\fB\-\-max\-depth\fR \fIMAX_DEPTH\fR] [\fB\-w\fR|\fB\-\-total\-width\fR \fITOTAL_WIDTH\fR] [\fB\-\-column\-width\fR \fITREE_WIDTH\fR \fIBAR_WIDTH\fR] [\fB\-m\fR|\fB\-\-min\-ratio\fR \fIMIN_RATIO\fR] [\fB\-\-no\-sort\fR] [\fB\-s\fR|\fB\-\-silent\-errors\fR] [\fB\-p\fR|\fB\-\-progress\fR] [\fB\-\-threads\fR \fITHREADS\fR] [\fB\-\-omit\-json\-shared\-details\fR] [\fB\-\-omit\-json\-shared\-summary\fR] [\fIFILES\fR]
86
.SH DESCRIPTION
97
Summarize disk usage of the set of files, recursively for directories.
108
.PP
119
Copyright: Apache\-2.0 © 2021 Hoàng Văn Khải <https://github.com/KSXGitHub/>
10+
.br
1211
Sponsor: https://github.com/sponsors/KSXGitHub
1312
.SH OPTIONS
1413
.TP
14+
[\fIFILES\fR]
15+
List of files and/or directories
16+
.TP
1517
\fB\-\-json\-input\fR
1618
Read JSON data from stdin
1719
.TP
@@ -33,7 +35,7 @@ metric: Use metric scale, i.e. 1K = 1000B, 1M = 1000K, and so on
3335
binary: Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on
3436
.RE
3537
.TP
36-
\fB\-H\fR, \fB\-\-deduplicate\-hardlinks\fR
38+
\fB\-H\fR, \fB\-\-deduplicate\-hardlinks\fR, \fB\-\-detect\-links\fR, \fB\-\-dedupe\-links\fR
3739
Detect and subtract the sizes of hardlinks from their parent directory totals
3840
.TP
3941
\fB\-x\fR, \fB\-\-one\-file\-system\fR
@@ -45,7 +47,7 @@ Print the tree top\-down instead of bottom\-up
4547
\fB\-\-align\-right\fR
4648
Set the root of the bars to the right
4749
.TP
48-
\fB\-q\fR, \fB\-\-quantity\fR \fI<QUANTITY>\fR [default: block\-size]
50+
\fB\-q\fR, \fB\-\-quantity\fR \fI<QUANTITY>\fR [default: block-size]
4951
Aspect of the files/directories to be measured
5052
.br
5153

@@ -60,10 +62,10 @@ block\-size: Measure block sizes (block\-count * 512B)
6062
block\-count: Count numbers of blocks
6163
.RE
6264
.TP
63-
\fB\-d\fR, \fB\-\-max\-depth\fR \fI<MAX_DEPTH>\fR [default: 10]
65+
\fB\-d\fR, \fB\-\-max\-depth\fR, \fB\-\-depth\fR \fI<MAX_DEPTH>\fR [default: 10]
6466
Maximum depth to display the data. Could be either "inf" or a positive integer
6567
.TP
66-
\fB\-w\fR, \fB\-\-total\-width\fR \fI<TOTAL_WIDTH>\fR
68+
\fB\-w\fR, \fB\-\-total\-width\fR, \fB\-\-width\fR \fI<TOTAL_WIDTH>\fR
6769
Width of the visualization
6870
.TP
6971
\fB\-\-column\-width\fR \fI<TREE_WIDTH>\fR\fI \fR\fI<BAR_WIDTH>\fR
@@ -75,7 +77,7 @@ Minimal size proportion required to appear
7577
\fB\-\-no\-sort\fR
7678
Do not sort the branches in the tree
7779
.TP
78-
\fB\-s\fR, \fB\-\-silent\-errors\fR
80+
\fB\-s\fR, \fB\-\-silent\-errors\fR, \fB\-\-no\-errors\fR
7981
Prevent filesystem error messages from appearing in stderr
8082
.TP
8183
\fB\-p\fR, \fB\-\-progress\fR
@@ -89,47 +91,61 @@ Do not output `.shared.details` in the JSON output
8991
.TP
9092
\fB\-\-omit\-json\-shared\-summary\fR
9193
Do not output `.shared.summary` in the JSON output
92-
.TP
93-
\fB\-h\fR, \fB\-\-help\fR
94-
Print help (see a summary with \*(Aq\-h\*(Aq)
95-
.TP
96-
\fB\-V\fR, \fB\-\-version\fR
97-
Print version
98-
.TP
99-
[\fIFILES\fR]
100-
List of files and/or directories
10194
.SH EXAMPLES
95+
.TP
10296
Show disk usage chart of current working directory
103-
$ pdu
104-
97+
.nf
98+
\fB$ pdu\fR
99+
.fi
100+
.TP
105101
Show disk usage chart of a single file or directory
106-
$ pdu path/to/file/or/directory
107-
102+
.nf
103+
\fB$ pdu path/to/file/or/directory\fR
104+
.fi
105+
.TP
108106
Compare disk usages of multiple files and/or directories
109-
$ pdu file.txt dir/
110-
107+
.nf
108+
\fB$ pdu file.txt dir/\fR
109+
.fi
110+
.TP
111111
Show chart in apparent sizes instead of block sizes
112-
$ pdu \-\-quantity=apparent\-size
113-
112+
.nf
113+
\fB$ pdu \-\-quantity=apparent\-size\fR
114+
.fi
115+
.TP
114116
Detect and subtract the sizes of hardlinks from their parent nodes
115-
$ pdu \-\-deduplicate\-hardlinks
116-
117+
.nf
118+
\fB$ pdu \-\-deduplicate\-hardlinks\fR
119+
.fi
120+
.TP
117121
Show sizes in plain numbers instead of metric units
118-
$ pdu \-\-bytes\-format=plain
119-
122+
.nf
123+
\fB$ pdu \-\-bytes\-format=plain\fR
124+
.fi
125+
.TP
120126
Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)
121-
$ pdu \-\-bytes\-format=binary
122-
127+
.nf
128+
\fB$ pdu \-\-bytes\-format=binary\fR
129+
.fi
130+
.TP
123131
Show disk usage chart of all entries regardless of size
124-
$ pdu \-\-min\-ratio=0
125-
132+
.nf
133+
\fB$ pdu \-\-min\-ratio=0\fR
134+
.fi
135+
.TP
126136
Only show disk usage chart of entries whose size is at least 5% of total
127-
$ pdu \-\-min\-ratio=0.05
128-
137+
.nf
138+
\fB$ pdu \-\-min\-ratio=0.05\fR
139+
.fi
140+
.TP
129141
Show disk usage data as JSON instead of chart
130-
$ pdu \-\-min\-ratio=0 \-\-max\-depth=inf \-\-json\-output | jq
131-
142+
.nf
143+
\fB$ pdu \-\-min\-ratio=0 \-\-max\-depth=inf \-\-json\-output | jq\fR
144+
.fi
145+
.TP
132146
Visualize existing JSON representation of disk usage data
133-
$ pdu \-\-json\-input < disk\-usage.json
147+
.nf
148+
\fB$ pdu \-\-json\-input < disk\-usage.json\fR
149+
.fi
134150
.SH VERSION
135151
v0.21.1

0 commit comments

Comments
 (0)