Skip to content

Commit 1fa57cc

Browse files
committed
fix(man): clean up EXAMPLES section formatting
Remove the redundant "Examples:" subheading and strip unnecessary 4-space indentation from the examples content in the generated man page. https://claude.ai/code/session_01CrXuWDMVQsiUBoy6ceACsF
1 parent 35dbf94 commit 1fa57cc

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

exports/pdu.1

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,38 +99,37 @@ Print version
9999
[\fIFILES\fR]
100100
List of files and/or directories
101101
.SH EXAMPLES
102-
Examples:
103-
Show disk usage chart of current working directory
104-
$ pdu
102+
Show disk usage chart of current working directory
103+
$ pdu
105104

106-
Show disk usage chart of a single file or directory
107-
$ pdu path/to/file/or/directory
105+
Show disk usage chart of a single file or directory
106+
$ pdu path/to/file/or/directory
108107

109-
Compare disk usages of multiple files and/or directories
110-
$ pdu file.txt dir/
108+
Compare disk usages of multiple files and/or directories
109+
$ pdu file.txt dir/
111110

112-
Show chart in apparent sizes instead of block sizes
113-
$ pdu \-\-quantity=apparent\-size
111+
Show chart in apparent sizes instead of block sizes
112+
$ pdu \-\-quantity=apparent\-size
114113

115-
Detect and subtract the sizes of hardlinks from their parent nodes
116-
$ pdu \-\-deduplicate\-hardlinks
114+
Detect and subtract the sizes of hardlinks from their parent nodes
115+
$ pdu \-\-deduplicate\-hardlinks
117116

118-
Show sizes in plain numbers instead of metric units
119-
$ pdu \-\-bytes\-format=plain
117+
Show sizes in plain numbers instead of metric units
118+
$ pdu \-\-bytes\-format=plain
120119

121-
Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)
122-
$ pdu \-\-bytes\-format=binary
120+
Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)
121+
$ pdu \-\-bytes\-format=binary
123122

124-
Show disk usage chart of all entries regardless of size
125-
$ pdu \-\-min\-ratio=0
123+
Show disk usage chart of all entries regardless of size
124+
$ pdu \-\-min\-ratio=0
126125

127-
Only show disk usage chart of entries whose size is at least 5% of total
128-
$ pdu \-\-min\-ratio=0.05
126+
Only show disk usage chart of entries whose size is at least 5% of total
127+
$ pdu \-\-min\-ratio=0.05
129128

130-
Show disk usage data as JSON instead of chart
131-
$ pdu \-\-min\-ratio=0 \-\-max\-depth=inf \-\-json\-output | jq
129+
Show disk usage data as JSON instead of chart
130+
$ pdu \-\-min\-ratio=0 \-\-max\-depth=inf \-\-json\-output | jq
132131

133-
Visualize existing JSON representation of disk usage data
134-
$ pdu \-\-json\-input < disk\-usage.json
132+
Visualize existing JSON representation of disk usage data
133+
$ pdu \-\-json\-input < disk\-usage.json
135134
.SH VERSION
136135
v0.21.1

src/man_page.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,35 @@ pub fn render_man_page() -> io::Result<String> {
1111
man.render(&mut buffer)?;
1212
let content = String::from_utf8(buffer)
1313
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;
14-
Ok(content.replace("\n.SH EXTRA\n", "\n.SH EXAMPLES\n"))
14+
Ok(postprocess_man_page(&content))
15+
}
16+
17+
fn postprocess_man_page(content: &str) -> String {
18+
let mut output = String::with_capacity(content.len());
19+
let mut in_examples = false;
20+
21+
for line in content.lines() {
22+
if line == ".SH EXTRA" {
23+
output.push_str(".SH EXAMPLES\n");
24+
in_examples = true;
25+
continue;
26+
}
27+
28+
if in_examples && line.starts_with(".SH ") {
29+
in_examples = false;
30+
}
31+
32+
if in_examples {
33+
let trimmed = line.strip_prefix(" ").unwrap_or(line);
34+
if trimmed == "Examples:" {
35+
continue;
36+
}
37+
output.push_str(trimmed);
38+
} else {
39+
output.push_str(line);
40+
}
41+
output.push('\n');
42+
}
43+
44+
output
1545
}

0 commit comments

Comments
 (0)