-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(mangen): Support flatten_help #5769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Most of these differences sound unrelated to flattening |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,46 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) { | |
} | ||
|
||
pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) { | ||
let name = cmd.get_bin_name().unwrap_or_else(|| cmd.get_name()); | ||
let mut line = vec![bold(name), roman(" ")]; | ||
let flatten = cmd.is_flatten_help_set(); | ||
let mut first = true; | ||
if !cmd.is_subcommand_required_set() || cmd.is_args_conflicts_with_subcommands_set() { | ||
let mut line = usage(cmd, cmd.get_bin_name().unwrap_or_else(|| cmd.get_name())); | ||
if cmd.has_subcommands() && !flatten { | ||
let (lhs, rhs) = subcommand_markers(cmd); | ||
line.push(roman(lhs)); | ||
line.push(italic( | ||
cmd.get_subcommand_value_name() | ||
.unwrap_or_else(|| subcommand_heading(cmd)) | ||
.to_lowercase(), | ||
)); | ||
line.push(roman(rhs)); | ||
} | ||
roff.text(line); | ||
first = false; | ||
} | ||
if flatten { | ||
let mut ord_v = Vec::new(); | ||
for subcommand in cmd.get_subcommands() { | ||
ord_v.push(( | ||
subcommand.get_display_order(), | ||
subcommand.get_bin_name().unwrap_or_else(|| cmd.get_name()), | ||
subcommand, | ||
)); | ||
} | ||
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't recursive but should be (same with |
||
ord_v.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1))); | ||
for (_, name, cmd) in ord_v { | ||
if !first { | ||
roff.control("br", []); | ||
} else { | ||
first = false; | ||
} | ||
roff.text(usage(cmd, name)); | ||
} | ||
} | ||
} | ||
|
||
fn usage(cmd: &clap::Command, name: &str) -> Vec<Inline> { | ||
let mut line = vec![bold(name), roman(" ")]; | ||
for opt in cmd.get_arguments().filter(|i| !i.is_hide_set()) { | ||
let (lhs, rhs) = option_markers(opt); | ||
match (opt.get_short(), opt.get_long()) { | ||
|
@@ -74,18 +111,7 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) { | |
line.push(roman(" ")); | ||
} | ||
|
||
if cmd.has_subcommands() { | ||
let (lhs, rhs) = subcommand_markers(cmd); | ||
line.push(roman(lhs)); | ||
line.push(italic( | ||
cmd.get_subcommand_value_name() | ||
.unwrap_or_else(|| subcommand_heading(cmd)) | ||
.to_lowercase(), | ||
)); | ||
line.push(roman(rhs)); | ||
} | ||
|
||
roff.text(line); | ||
line | ||
} | ||
|
||
pub(crate) fn options(roff: &mut Roff, items: &[&Arg]) { | ||
|
@@ -218,6 +244,26 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) { | |
} | ||
} | ||
|
||
pub(crate) fn flat_subcommands(roff: &mut Roff, cmd: &clap::Command) { | ||
for sub in cmd.get_subcommands().filter(|s| !s.is_hide_set()) { | ||
roff.control("TP", []); | ||
|
||
let mut line = usage(sub, sub.get_name()); | ||
|
||
if let Some(about) = sub.get_long_about().or_else(|| sub.get_about()) { | ||
line.push(roman("\n")); | ||
line.push(roman(about.to_string())); | ||
} | ||
|
||
if let Some(after_help) = sub.get_after_help() { | ||
line.push(roman("\n")); | ||
line.push(roman(after_help.to_string())); | ||
} | ||
|
||
roff.text(line); | ||
} | ||
} | ||
|
||
pub(crate) fn version(cmd: &clap::Command) -> String { | ||
format!( | ||
"v{}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR <\fB\-\-parent\fR> [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent test\fR <\fB\-\-child\fR> [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBtest\fR <\fB\-\-child\fR> [\fB\-h\fR|\fB\-\-help\fR] | ||
test command | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent test\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
test command | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH my-app 1 "my-app " | ||
.SH NAME | ||
my\-app | ||
.SH SYNOPSIS | ||
\fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBmy\-app test\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBmy\-app help\fR | ||
.SH DESCRIPTION | ||
.SH OPTIONS | ||
.TP | ||
\fB\-c\fR | ||
|
||
.TP | ||
\fB\-v\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBtest\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
Subcommand | ||
with a second line | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent test\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
bar | ||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help (see a summary with \*(Aq\-h\*(Aq) | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
long some | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH my-app 1 "my-app " | ||
.SH NAME | ||
my\-app | ||
.SH SYNOPSIS | ||
\fBmy\-app test\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBmy\-app help\fR | ||
.SH DESCRIPTION | ||
.SH OPTIONS | ||
.TP | ||
\fB\-c\fR | ||
|
||
.TP | ||
\fB\-v\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBtest\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
Subcommand | ||
with a second line | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child3\fR [\fB\-\-child3\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child1 command | ||
.TP | ||
\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child2 command | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child3\fR [\fB\-\-child3\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child1 command | ||
.TP | ||
\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child2 command | ||
.TP | ||
\fBchild3\fR [\fB\-\-child3\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child3 command | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child3\fR [\fB\-\-child3\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child1 command | ||
.TP | ||
\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
child2 command | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.ie \n(.g .ds Aq \(aq | ||
.el .ds Aq ' | ||
.TH parent 1 "parent " | ||
.SH NAME | ||
parent \- parent command | ||
.SH SYNOPSIS | ||
\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent child1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] | ||
.br | ||
\fBparent help\fR | ||
.SH DESCRIPTION | ||
parent command | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-parent\fR | ||
|
||
.TP | ||
\fB\-h\fR, \fB\-\-help\fR | ||
Print help | ||
.SH SUBCOMMANDS | ||
.TP | ||
\fBhelp\fR | ||
Print this message or the help of the given subcommand(s) |
Uh oh!
There was an error while loading. Please reload this page.