Skip to content

Commit

Permalink
test(help): Show how hide and flatten mix
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 27, 2023
1 parent 5c8f8d5 commit b656198
Showing 1 changed file with 116 additions and 7 deletions.
123 changes: 116 additions & 7 deletions tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,88 @@ Print this message or the help of the given subcommand(s)
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]
fn flatten_recursive() {
static EXPECTED: &str = "\
Expand All @@ -3324,7 +3406,7 @@ Usage: parent [OPTIONS]
parent child1 grandchild3 [OPTIONS]
parent child1 help [COMMAND]
parent child2 [OPTIONS]
parent child3 [OPTIONS]
parent child3 [OPTIONS] [COMMAND]
parent help [COMMAND]...
Options:
Expand Down Expand Up @@ -3379,11 +3461,6 @@ child2 command
--child2 <child>
-h, --help Print help
parent child3:
child3 command
--child3 <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)
Expand Down Expand Up @@ -3436,8 +3513,40 @@ Print this message or the help of the given subcommand(s)
)
.subcommand(
Command::new("child3")
.hide(true)
.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);
}
Expand Down

0 comments on commit b656198

Please sign in to comment.