Skip to content

Commit 89dea44

Browse files
committed
chore(mangen): Split out usage() function
The function prints the usage of a (sub)command. Signed-off-by: Paul Spooren <mail@aparcar.org>
1 parent 70d80fc commit 89dea44

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

clap_mangen/src/render.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,24 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) {
3232
pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
3333
let name = cmd.get_bin_name().unwrap_or_else(|| cmd.get_name());
3434
let mut line = vec![bold(name), roman(" ")];
35+
let mut line = usage(cmd, name);
3536

37+
if cmd.has_subcommands() && !flatten {
38+
let (lhs, rhs) = subcommand_markers(cmd);
39+
line.push(roman(lhs));
40+
line.push(italic(
41+
cmd.get_subcommand_value_name()
42+
.unwrap_or_else(|| subcommand_heading(cmd))
43+
.to_lowercase(),
44+
));
45+
line.push(roman(rhs));
46+
}
47+
roff.text(line);
48+
}
49+
}
50+
51+
fn usage(cmd: &clap::Command, name: &str) -> Vec<Inline> {
52+
let mut line = vec![bold(name), roman(" ")];
3653
for opt in cmd.get_arguments().filter(|i| !i.is_hide_set()) {
3754
let (lhs, rhs) = option_markers(opt);
3855
match (opt.get_short(), opt.get_long()) {
@@ -74,18 +91,7 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
7491
line.push(roman(" "));
7592
}
7693

77-
if cmd.has_subcommands() {
78-
let (lhs, rhs) = subcommand_markers(cmd);
79-
line.push(roman(lhs));
80-
line.push(italic(
81-
cmd.get_subcommand_value_name()
82-
.unwrap_or_else(|| subcommand_heading(cmd))
83-
.to_lowercase(),
84-
));
85-
line.push(roman(rhs));
86-
}
87-
88-
roff.text(line);
94+
line
8995
}
9096

9197
pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {

0 commit comments

Comments
 (0)