Skip to content

Commit 2641238

Browse files
committed
fix(man): escape default values in roff and fix .TH field order
Apply roff_escape to default values so hyphens render consistently (e.g. block-size becomes block\-size). Also fix .TH header to place the version string in the source field instead of the date field per man(7) convention. https://claude.ai/code/session_01CrXuWDMVQsiUBoy6ceACsF
1 parent d901315 commit 2641238

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

exports/pdu.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH pdu 1 "pdu 0.21.1"
1+
.TH pdu 1 "" "pdu 0.21.1"
22
.SH NAME
33
pdu \- Summarize disk usage of the set of files, recursively for directories.
44
.SH SYNOPSIS
@@ -58,7 +58,7 @@ Print the tree top\-down instead of bottom\-up
5858
\fB\-\-align\-right\fR
5959
Set the root of the bars to the right
6060
.TP
61-
\fB\-q\fR, \fB\-\-quantity\fR \fI<QUANTITY>\fR [default: block-size]
61+
\fB\-q\fR, \fB\-\-quantity\fR \fI<QUANTITY>\fR [default: block\-size]
6262
Aspect of the files/directories to be measured
6363
.RS
6464
.TP

src/man_page.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::args::Args;
22
use clap::{Arg, ArgAction, Command, CommandFactory};
33
use itertools::Itertools;
4-
use std::{borrow::Cow, collections::BTreeMap, fmt::Write};
4+
use std::{collections::BTreeMap, fmt::Write};
55

66
/// A map from argument ID to the set of argument IDs it conflicts with (bidirectional).
77
type ConflictMap = BTreeMap<String, Vec<String>>;
@@ -59,7 +59,7 @@ fn roff_escape(text: &str) -> String {
5959
fn render_title(out: &mut String, command: &Command) {
6060
let name = command.get_name();
6161
let version = command.get_version().unwrap_or_default();
62-
writeln!(out, ".TH {name} 1 \"{name} {version}\"").unwrap();
62+
writeln!(out, ".TH {name} 1 \"\" \"{name} {version}\"").unwrap();
6363
}
6464

6565
fn render_name_section(out: &mut String, command: &Command) {
@@ -236,19 +236,19 @@ fn render_value_hint(arg: &Arg) -> String {
236236
.map(roff_escape)
237237
.map(|name| format!("\\fI<{name}>\\fR"))
238238
.join(" ");
239-
let defaults: Vec<_> = arg
239+
let defaults = arg
240240
.get_default_values()
241241
.iter()
242242
.map(|value| value.to_string_lossy())
243-
.map(Cow::into_owned)
244-
.collect();
243+
.map(|value| roff_escape(&value))
244+
.join(", ");
245245
let hide_defaults = defaults.is_empty()
246246
|| arg.is_hide_default_value_set()
247247
|| matches!(arg.get_action(), ArgAction::SetTrue);
248248
if hide_defaults {
249249
value_part
250250
} else {
251-
format!("{value_part} [default: {}]", defaults.join(", "))
251+
format!("{value_part} [default: {defaults}]")
252252
}
253253
}
254254

0 commit comments

Comments
 (0)