test(help): Show how hide and flatten mix

This commit is contained in:
Ed Page 2023-11-27 10:38:05 -06:00
parent 5c8f8d5f65
commit b6561983a0

View file

@ -3308,6 +3308,88 @@ Print this message or the help of the given subcommand(s)
utils::assert_output(cmd, "parent -h", EXPECTED, false); utils::assert_output(cmd, "parent -h", EXPECTED, false);
} }
#[test]
fn flatten_single_hidden_command() {
static EXPECTED: &str = "\
parent command
Usage: parent [OPTIONS]
parent child1 [OPTIONS]
parent help [COMMAND]...
Options:
--parent <parent>
-h, --help Print help
parent help:
Print this message or the help of the given subcommand(s)
[COMMAND]... Print help for the subcommand(s)
";
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")),
);
utils::assert_output(cmd, "parent -h", EXPECTED, false);
}
#[test]
fn flatten_hidden_command() {
static EXPECTED: &str = "\
parent command
Usage: parent [OPTIONS]
parent child1 [OPTIONS]
parent child2 [OPTIONS]
parent child3 [OPTIONS]
parent help [COMMAND]...
Options:
--parent <parent>
-h, --help Print help
parent child1:
child1 command
--child1 <child>
-h, --help Print help
parent child2:
child2 command
--child2 <child>
-h, --help Print help
parent help:
Print this message or the help of the given subcommand(s)
[COMMAND]... Print help for the subcommand(s)
";
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")),
);
utils::assert_output(cmd, "parent -h", EXPECTED, false);
}
#[test] #[test]
fn flatten_recursive() { fn flatten_recursive() {
static EXPECTED: &str = "\ static EXPECTED: &str = "\
@ -3324,7 +3406,7 @@ Usage: parent [OPTIONS]
parent child1 grandchild3 [OPTIONS] parent child1 grandchild3 [OPTIONS]
parent child1 help [COMMAND] parent child1 help [COMMAND]
parent child2 [OPTIONS] parent child2 [OPTIONS]
parent child3 [OPTIONS] parent child3 [OPTIONS] [COMMAND]
parent help [COMMAND]... parent help [COMMAND]...
Options: Options:
@ -3379,11 +3461,6 @@ child2 command
--child2 <child> --child2 <child>
-h, --help Print help -h, --help Print help
parent child3:
child3 command
--child3 <child>
-h, --help Print help
parent help: parent help:
Print this message or the help of the given subcommand(s) Print this message or the help of the given subcommand(s)
[COMMAND]... Print help for the subcommand(s) [COMMAND]... Print help for the subcommand(s)
@ -3436,8 +3513,40 @@ Print this message or the help of the given subcommand(s)
) )
.subcommand( .subcommand(
Command::new("child3") Command::new("child3")
.hide(true)
.about("child3 command") .about("child3 command")
.arg(Arg::new("child").long("child3")), .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")),
),
); );
utils::assert_output(cmd, "parent -h", EXPECTED, false); utils::assert_output(cmd, "parent -h", EXPECTED, false);
} }