From ecd76b5e0b34c1f07cf88960955a19497abf85f5 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 17 Oct 2024 14:53:22 +0200 Subject: [PATCH 1/4] test(mangen): Add test for flatten_help This test shows that the output stays the same independent of the value of `flatten_help`. Further commits may implement `flatten_help` for `clap_mangen`. Signed-off-by: Paul Spooren --- clap_mangen/tests/snapshots/flatten_help.roff | 26 ++++++++++++++ .../flatten_help_subcommand_required.roff | 26 ++++++++++++++ clap_mangen/tests/testsuite/roff.rs | 36 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 clap_mangen/tests/snapshots/flatten_help.roff create mode 100644 clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff diff --git a/clap_mangen/tests/snapshots/flatten_help.roff b/clap_mangen/tests/snapshots/flatten_help.roff new file mode 100644 index 00000000000..e9ab64a9d6f --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_help.roff @@ -0,0 +1,26 @@ +.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] [\fIsubcommands\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 +my\-app\-test(1) +Subcommand +with a second line +.TP +my\-app\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff b/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff new file mode 100644 index 00000000000..f24d23a888a --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff @@ -0,0 +1,26 @@ +.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] <\fIsubcommands\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 +my\-app\-test(1) +Subcommand +with a second line +.TP +my\-app\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/testsuite/roff.rs b/clap_mangen/tests/testsuite/roff.rs index 6adfcd238fc..99addd3b765 100644 --- a/clap_mangen/tests/testsuite/roff.rs +++ b/clap_mangen/tests/testsuite/roff.rs @@ -112,3 +112,39 @@ fn value_name_without_arg() { cmd, ); } + +#[test] +fn flatten_help_false() { + let name = "my-app"; + let cmd = common::basic_command(name).flatten_help(false); + common::assert_matches(snapbox::file!["../snapshots/basic.bash.roff"], cmd); +} + +#[test] +fn flatten_help_true() { + let name = "my-app"; + let cmd = common::basic_command(name).flatten_help(true); + common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); +} + +#[test] +fn flatten_help_true_subcommand_required_true() { + let name = "my-app"; + let cmd = common::basic_command(name) + .flatten_help(true) + .subcommand_required(true); + common::assert_matches( + snapbox::file!["../snapshots/flatten_help_subcommand_required.roff"], + cmd, + ); +} + +#[test] +fn flatten_help_true_subcommand_args_conflicts_with_subcommands() { + let name = "my-app"; + let cmd = common::basic_command(name) + .flatten_help(true) + .subcommand_required(false) + .args_conflicts_with_subcommands(false); + common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); +} From 382996453541e047235ee7369d38ebcb6e0ce445 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Wed, 23 Oct 2024 12:13:07 +0200 Subject: [PATCH 2/4] test(mangen): Add all flatten related tests from builder Add all tests from tests/builder/help.rs to mangen, too. Signed-off-by: Paul Spooren --- .../tests/snapshots/flatten_arg_required.roff | 23 ++ .../tests/snapshots/flatten_basic.roff | 23 ++ .../tests/snapshots/flatten_help_cmd.roff | 23 ++ .../snapshots/flatten_hidden_command.roff | 26 ++ .../snapshots/flatten_not_recursive.roff | 29 ++ .../tests/snapshots/flatten_recursive.roff | 26 ++ .../flatten_single_hidden_command.roff | 20 ++ ..._with_args_conflicts_with_subcommands.roff | 23 ++ .../flatten_with_external_subcommand.roff | 23 ++ .../tests/snapshots/flatten_with_global.roff | 23 ++ .../flatten_with_subcommand_required.roff | 23 ++ .../flatten_without_subcommands.roff | 16 + clap_mangen/tests/testsuite/roff.rs | 321 ++++++++++++++++++ 13 files changed, 599 insertions(+) create mode 100644 clap_mangen/tests/snapshots/flatten_arg_required.roff create mode 100644 clap_mangen/tests/snapshots/flatten_basic.roff create mode 100644 clap_mangen/tests/snapshots/flatten_help_cmd.roff create mode 100644 clap_mangen/tests/snapshots/flatten_hidden_command.roff create mode 100644 clap_mangen/tests/snapshots/flatten_not_recursive.roff create mode 100644 clap_mangen/tests/snapshots/flatten_recursive.roff create mode 100644 clap_mangen/tests/snapshots/flatten_single_hidden_command.roff create mode 100644 clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff create mode 100644 clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff create mode 100644 clap_mangen/tests/snapshots/flatten_with_global.roff create mode 100644 clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff create mode 100644 clap_mangen/tests/snapshots/flatten_without_subcommands.roff diff --git a/clap_mangen/tests/snapshots/flatten_arg_required.roff b/clap_mangen/tests/snapshots/flatten_arg_required.roff new file mode 100644 index 00000000000..f8354f45e98 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_arg_required.roff @@ -0,0 +1,23 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_basic.roff b/clap_mangen/tests/snapshots/flatten_basic.roff new file mode 100644 index 00000000000..f4d61649fd2 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_basic.roff @@ -0,0 +1,23 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_help_cmd.roff b/clap_mangen/tests/snapshots/flatten_help_cmd.roff new file mode 100644 index 00000000000..8f713a455fb --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_help_cmd.roff @@ -0,0 +1,23 @@ +.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] [\fIsubcommands\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 +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_hidden_command.roff b/clap_mangen/tests/snapshots/flatten_hidden_command.roff new file mode 100644 index 00000000000..c65834a21af --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_hidden_command.roff @@ -0,0 +1,26 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-child1(1) +child1 command +.TP +parent\-child2(1) +child2 command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_not_recursive.roff b/clap_mangen/tests/snapshots/flatten_not_recursive.roff new file mode 100644 index 00000000000..3551d38fe34 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_not_recursive.roff @@ -0,0 +1,29 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-child1(1) +child1 command +.TP +parent\-child2(1) +child2 command +.TP +parent\-child3(1) +child3 command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_recursive.roff b/clap_mangen/tests/snapshots/flatten_recursive.roff new file mode 100644 index 00000000000..c65834a21af --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_recursive.roff @@ -0,0 +1,26 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-child1(1) +child1 command +.TP +parent\-child2(1) +child2 command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff b/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff new file mode 100644 index 00000000000..6880013df6f --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff @@ -0,0 +1,20 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff b/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff new file mode 100644 index 00000000000..2536001840f --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff @@ -0,0 +1,23 @@ +.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] <\fIsubcommands\fR> +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff b/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff new file mode 100644 index 00000000000..f4d61649fd2 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff @@ -0,0 +1,23 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_global.roff b/clap_mangen/tests/snapshots/flatten_with_global.roff new file mode 100644 index 00000000000..f4d61649fd2 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_with_global.roff @@ -0,0 +1,23 @@ +.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] [\fIsubcommands\fR] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff b/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff new file mode 100644 index 00000000000..2536001840f --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff @@ -0,0 +1,23 @@ +.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] <\fIsubcommands\fR> +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help +.SH SUBCOMMANDS +.TP +parent\-test(1) +test command +.TP +parent\-help(1) +Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_without_subcommands.roff b/clap_mangen/tests/snapshots/flatten_without_subcommands.roff new file mode 100644 index 00000000000..d2855bfb428 --- /dev/null +++ b/clap_mangen/tests/snapshots/flatten_without_subcommands.roff @@ -0,0 +1,16 @@ +.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] +.SH DESCRIPTION +parent command +.SH OPTIONS +.TP +\fB\-\-parent\fR + +.TP +\fB\-h\fR, \fB\-\-help\fR +Print help diff --git a/clap_mangen/tests/testsuite/roff.rs b/clap_mangen/tests/testsuite/roff.rs index 99addd3b765..711916c5a5c 100644 --- a/clap_mangen/tests/testsuite/roff.rs +++ b/clap_mangen/tests/testsuite/roff.rs @@ -1,4 +1,5 @@ use crate::common; +use clap::{Arg, Command}; #[test] fn basic() { @@ -148,3 +149,323 @@ fn flatten_help_true_subcommand_args_conflicts_with_subcommands() { .args_conflicts_with_subcommands(false); common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); } + +#[test] +fn flatten_basic() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child")), + ); + + common::assert_matches(snapbox::file!["../snapshots/flatten_basic.roff"], cmd); +} + +#[test] +fn flatten_help_cmd() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg( + Arg::new("parent") + .long("parent") + .help("foo") + .long_help("bar"), + ) + .subcommand( + Command::new("test") + .about("test command") + .long_about("long some") + .arg(Arg::new("child").long("child").help("foo").long_help("bar")), + ); + + common::assert_matches(snapbox::file!["../snapshots/flatten_help_cmd.roff"], cmd); +} + +#[test] +fn flatten_with_global() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent").global(true)) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child")), + ); + + common::assert_matches(snapbox::file!["../snapshots/flatten_with_global.roff"], cmd); +} + +#[test] +fn flatten_arg_required() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent").required(true)) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child").required(true)), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_arg_required.roff"], + cmd, + ); +} + +#[test] +fn flatten_with_external_subcommand() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .allow_external_subcommands(true) + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_with_external_subcommand.roff"], + cmd, + ); +} + +#[test] +fn flatten_without_subcommands() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_without_subcommands.roff"], + cmd, + ); +} + +#[test] +fn flatten_with_subcommand_required() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .subcommand_required(true) + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_with_subcommand_required.roff"], + cmd, + ); +} + +#[test] +fn flatten_with_args_conflicts_with_subcommands() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .subcommand_required(true) + .args_conflicts_with_subcommands(true) + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("test") + .about("test command") + .arg(Arg::new("child").long("child")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_with_args_conflicts_with_subcommands.roff"], + cmd, + ); +} + +#[test] +fn flatten_single_hidden_command() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("child1") + .hide(true) + .about("child1 command") + .arg(Arg::new("child").long("child1")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_single_hidden_command.roff"], + cmd, + ); +} + +#[test] +fn flatten_hidden_command() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("child1") + .about("child1 command") + .arg(Arg::new("child").long("child1")), + ) + .subcommand( + Command::new("child2") + .about("child2 command") + .arg(Arg::new("child").long("child2")), + ) + .subcommand( + Command::new("child3") + .hide(true) + .about("child3 command") + .arg(Arg::new("child").long("child3")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_hidden_command.roff"], + cmd, + ); +} + +#[test] +fn flatten_recursive() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("child1") + .flatten_help(true) + .about("child1 command") + .arg(Arg::new("child").long("child1")) + .subcommand( + Command::new("grandchild1") + .flatten_help(true) + .about("grandchild1 command") + .arg(Arg::new("grandchild").long("grandchild1")) + .subcommand( + Command::new("greatgrandchild1") + .about("greatgrandchild1 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild1")), + ) + .subcommand( + Command::new("greatgrandchild2") + .about("greatgrandchild2 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild2")), + ) + .subcommand( + Command::new("greatgrandchild3") + .about("greatgrandchild3 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild3")), + ), + ) + .subcommand( + Command::new("grandchild2") + .about("grandchild2 command") + .arg(Arg::new("grandchild").long("grandchild2")), + ) + .subcommand( + Command::new("grandchild3") + .about("grandchild3 command") + .arg(Arg::new("grandchild").long("grandchild3")), + ), + ) + .subcommand( + Command::new("child2") + .about("child2 command") + .arg(Arg::new("child").long("child2")), + ) + .subcommand( + Command::new("child3") + .hide(true) + .about("child3 command") + .arg(Arg::new("child").long("child3")) + .subcommand( + Command::new("grandchild1") + .flatten_help(true) + .about("grandchild1 command") + .arg(Arg::new("grandchild").long("grandchild1")) + .subcommand( + Command::new("greatgrandchild1") + .about("greatgrandchild1 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild1")), + ) + .subcommand( + Command::new("greatgrandchild2") + .about("greatgrandchild2 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild2")), + ) + .subcommand( + Command::new("greatgrandchild3") + .about("greatgrandchild3 command") + .arg(Arg::new("greatgrandchild").long("greatgrandchild3")), + ), + ) + .subcommand( + Command::new("grandchild2") + .about("grandchild2 command") + .arg(Arg::new("grandchild").long("grandchild2")), + ) + .subcommand( + Command::new("grandchild3") + .about("grandchild3 command") + .arg(Arg::new("grandchild").long("grandchild3")), + ), + ); + + common::assert_matches(snapbox::file!["../snapshots/flatten_recursive.roff"], cmd); +} + +#[test] +fn flatten_not_recursive() { + let cmd = Command::new("parent") + .flatten_help(true) + .about("parent command") + .arg(Arg::new("parent").long("parent")) + .subcommand( + Command::new("child1") + .about("child1 command") + .arg(Arg::new("child").long("child1")) + .subcommand( + Command::new("grandchild1") + .about("grandchild1 command") + .arg(Arg::new("grandchild").long("grandchild1")), + ) + .subcommand( + Command::new("grandchild2") + .about("grandchild2 command") + .arg(Arg::new("grandchild").long("grandchild2")), + ) + .subcommand( + Command::new("grandchild3") + .about("grandchild3 command") + .arg(Arg::new("grandchild").long("grandchild3")), + ), + ) + .subcommand( + Command::new("child2") + .about("child2 command") + .arg(Arg::new("child").long("child2")), + ) + .subcommand( + Command::new("child3") + .about("child3 command") + .arg(Arg::new("child").long("child3")), + ); + + common::assert_matches( + snapbox::file!["../snapshots/flatten_not_recursive.roff"], + cmd, + ); +} From 78a738b94f453cdde6478a389f90c58ab69a18d9 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 17 Oct 2024 14:57:06 +0200 Subject: [PATCH 3/4] refactor(mangen): Split out usage() function The function prints the usage of a (sub)command. Signed-off-by: Paul Spooren --- clap_mangen/src/render.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index c48d13a4812..95ee476d471 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -31,8 +31,23 @@ 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 mut line = usage(cmd, name); + + 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); +} +fn usage(cmd: &clap::Command, name: &str) -> Vec { + 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 +89,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]) { From 11d560f1f74a7ce3b91cfad6417f302b7d3ff187 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 10 Feb 2025 20:06:12 +0000 Subject: [PATCH 4/4] feat(mangen): Support flatten_help The `flatten_help` argument combines all subcommands on a single page. Until now this wasn't supported for `mangen`. With this command the sections `SYNOPSIS` as well as `SUBCOMMANDS` are changed to imitate the style of `git stash --help`. Differences between flattened `--help` and the flattened man: * `--help` prints the description at the very beginning while Man uses a section called DESCRIPTION below the USAGE. * `--help` prints placeholder `[OPTIONS]` while Man prints all options * `--help` prints positional options (aka arguments) in its own section called arguments while Man prints them at the end of OPTIONS. * `--help` prints subcommands as their own section after the options section while Man uses an extra section called SUBCOMMANDS * `--help` prints `after_long_help` at the very end while Man uses the section EXTRA which comes before the sections VERSION and AUTHORS Signed-off-by: Paul Spooren --- clap_mangen/src/lib.rs | 6 +- clap_mangen/src/render.rs | 68 +++++++++++++++---- .../tests/snapshots/flatten_arg_required.roff | 10 ++- .../tests/snapshots/flatten_basic.roff | 10 ++- clap_mangen/tests/snapshots/flatten_help.roff | 10 ++- .../tests/snapshots/flatten_help_cmd.roff | 12 ++-- .../flatten_help_subcommand_required.roff | 8 ++- .../snapshots/flatten_hidden_command.roff | 16 +++-- .../snapshots/flatten_not_recursive.roff | 18 +++-- .../tests/snapshots/flatten_recursive.roff | 16 +++-- .../flatten_single_hidden_command.roff | 8 ++- ..._with_args_conflicts_with_subcommands.roff | 10 ++- .../flatten_with_external_subcommand.roff | 10 ++- .../tests/snapshots/flatten_with_global.roff | 10 ++- .../flatten_with_subcommand_required.roff | 8 ++- 15 files changed, 163 insertions(+), 57 deletions(-) diff --git a/clap_mangen/src/lib.rs b/clap_mangen/src/lib.rs index 2e11a94afa2..e54dc050b7f 100644 --- a/clap_mangen/src/lib.rs +++ b/clap_mangen/src/lib.rs @@ -289,7 +289,11 @@ impl Man { fn _render_subcommands_section(&self, roff: &mut Roff) { let heading = subcommand_heading(&self.cmd); roff.control("SH", [heading]); - render::subcommands(roff, &self.cmd, &self.section); + if self.cmd.is_flatten_help_set() { + render::flat_subcommands(roff, &self.cmd); + } else { + render::subcommands(roff, &self.cmd, &self.section); + } } /// Render the EXTRA section into the writer. diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index 95ee476d471..a8c9db75408 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -30,20 +30,42 @@ 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 = usage(cmd, name); - - 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)); + 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, + )); + } + 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)); + } } - roff.text(line); } fn usage(cmd: &clap::Command, name: &str) -> Vec { @@ -222,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{}", diff --git a/clap_mangen/tests/snapshots/flatten_arg_required.roff b/clap_mangen/tests/snapshots/flatten_arg_required.roff index f8354f45e98..4e3016bba1c 100644 --- a/clap_mangen/tests/snapshots/flatten_arg_required.roff +++ b/clap_mangen/tests/snapshots/flatten_arg_required.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR <\fB\-\-parent\fR> [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,8 +20,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR <\fB\-\-child\fR> [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_basic.roff b/clap_mangen/tests/snapshots/flatten_basic.roff index f4d61649fd2..be64adbdd50 100644 --- a/clap_mangen/tests/snapshots/flatten_basic.roff +++ b/clap_mangen/tests/snapshots/flatten_basic.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,8 +20,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_help.roff b/clap_mangen/tests/snapshots/flatten_help.roff index e9ab64a9d6f..8ed198d8e03 100644 --- a/clap_mangen/tests/snapshots/flatten_help.roff +++ b/clap_mangen/tests/snapshots/flatten_help.roff @@ -4,7 +4,11 @@ .SH NAME my\-app .SH SYNOPSIS -\fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -18,9 +22,9 @@ my\-app Print help .SH SUBCOMMANDS .TP -my\-app\-test(1) +\fBtest\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] Subcommand with a second line .TP -my\-app\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_help_cmd.roff b/clap_mangen/tests/snapshots/flatten_help_cmd.roff index 8f713a455fb..23028212879 100644 --- a/clap_mangen/tests/snapshots/flatten_help_cmd.roff +++ b/clap_mangen/tests/snapshots/flatten_help_cmd.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,8 +20,8 @@ bar Print help (see a summary with \*(Aq\-h\*(Aq) .SH SUBCOMMANDS .TP -parent\-test(1) -test command +\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] +long some .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff b/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff index f24d23a888a..e2dd9cc9a9f 100644 --- a/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff +++ b/clap_mangen/tests/snapshots/flatten_help_subcommand_required.roff @@ -4,7 +4,9 @@ .SH NAME my\-app .SH SYNOPSIS -\fBmy\-app\fR [\fB\-c \fR] [\fB\-v \fR] [\fB\-h\fR|\fB\-\-help\fR] <\fIsubcommands\fR> +\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 @@ -18,9 +20,9 @@ my\-app Print help .SH SUBCOMMANDS .TP -my\-app\-test(1) +\fBtest\fR [\fB\-d \fR]... [\fB\-c \fR] [\fB\-h\fR|\fB\-\-help\fR] Subcommand with a second line .TP -my\-app\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_hidden_command.roff b/clap_mangen/tests/snapshots/flatten_hidden_command.roff index c65834a21af..21ef1ab791f 100644 --- a/clap_mangen/tests/snapshots/flatten_hidden_command.roff +++ b/clap_mangen/tests/snapshots/flatten_hidden_command.roff @@ -4,7 +4,15 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,11 +24,11 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-child1(1) +\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] child1 command .TP -parent\-child2(1) +\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] child2 command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_not_recursive.roff b/clap_mangen/tests/snapshots/flatten_not_recursive.roff index 3551d38fe34..c72e34138bb 100644 --- a/clap_mangen/tests/snapshots/flatten_not_recursive.roff +++ b/clap_mangen/tests/snapshots/flatten_not_recursive.roff @@ -4,7 +4,15 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,14 +24,14 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-child1(1) +\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] child1 command .TP -parent\-child2(1) +\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] child2 command .TP -parent\-child3(1) +\fBchild3\fR [\fB\-\-child3\fR] [\fB\-h\fR|\fB\-\-help\fR] child3 command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_recursive.roff b/clap_mangen/tests/snapshots/flatten_recursive.roff index c65834a21af..21ef1ab791f 100644 --- a/clap_mangen/tests/snapshots/flatten_recursive.roff +++ b/clap_mangen/tests/snapshots/flatten_recursive.roff @@ -4,7 +4,15 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,11 +24,11 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-child1(1) +\fBchild1\fR [\fB\-\-child1\fR] [\fB\-h\fR|\fB\-\-help\fR] child1 command .TP -parent\-child2(1) +\fBchild2\fR [\fB\-\-child2\fR] [\fB\-h\fR|\fB\-\-help\fR] child2 command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff b/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff index 6880013df6f..aef2e4c39c3 100644 --- a/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff +++ b/clap_mangen/tests/snapshots/flatten_single_hidden_command.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,5 +20,5 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff b/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff index 2536001840f..be64adbdd50 100644 --- a/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff +++ b/clap_mangen/tests/snapshots/flatten_with_args_conflicts_with_subcommands.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] <\fIsubcommands\fR> +\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 @@ -16,8 +20,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff b/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff index f4d61649fd2..be64adbdd50 100644 --- a/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff +++ b/clap_mangen/tests/snapshots/flatten_with_external_subcommand.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\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 @@ -16,8 +20,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_global.roff b/clap_mangen/tests/snapshots/flatten_with_global.roff index f4d61649fd2..e9e273518f2 100644 --- a/clap_mangen/tests/snapshots/flatten_with_global.roff +++ b/clap_mangen/tests/snapshots/flatten_with_global.roff @@ -4,7 +4,11 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIsubcommands\fR] +\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] +.br +\fBparent test\fR [\fB\-\-child\fR] [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] +.br +\fBparent help\fR .SH DESCRIPTION parent command .SH OPTIONS @@ -16,8 +20,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR [\fB\-\-child\fR] [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s) diff --git a/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff b/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff index 2536001840f..c6802089606 100644 --- a/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff +++ b/clap_mangen/tests/snapshots/flatten_with_subcommand_required.roff @@ -4,7 +4,9 @@ .SH NAME parent \- parent command .SH SYNOPSIS -\fBparent\fR [\fB\-\-parent\fR] [\fB\-h\fR|\fB\-\-help\fR] <\fIsubcommands\fR> +\fBparent test\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] +.br +\fBparent help\fR .SH DESCRIPTION parent command .SH OPTIONS @@ -16,8 +18,8 @@ parent command Print help .SH SUBCOMMANDS .TP -parent\-test(1) +\fBtest\fR [\fB\-\-child\fR] [\fB\-h\fR|\fB\-\-help\fR] test command .TP -parent\-help(1) +\fBhelp\fR Print this message or the help of the given subcommand(s)