Skip to content

Commit

Permalink
fix(help): Help subcommands usage includes requires arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 30, 2022
1 parent 37ebb71 commit 1452c1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
26 changes: 7 additions & 19 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,20 +613,15 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
) -> ClapResult<ParseResult> {
debug!("Parser::parse_help_subcommand");

let mut bin_name = self
.cmd
.get_bin_name()
.unwrap_or_else(|| self.cmd.get_name())
.to_owned();

let mut cmd = self.cmd.clone();
let mut sc = {
let mut sc = self.cmd.clone();
let mut sc = &mut cmd;

for cmd in cmds {
sc = if let Some(c) = sc.find_subcommand(cmd) {
c
} else if let Some(c) = sc.find_subcommand(&cmd.to_string_lossy()) {
c
sc = if let Some(sc_name) =
sc.find_subcommand(cmd).map(|sc| sc.get_name().to_owned())
{
sc._build_subcommand(&sc_name).unwrap()
} else {
return Err(ClapError::unrecognized_subcommand(
self.cmd,
Expand All @@ -636,18 +631,11 @@ impl<'help, 'cmd> Parser<'help, 'cmd> {
.unwrap_or_else(|| self.cmd.get_name())
.to_owned(),
));
}
.clone();

sc._build_self();
bin_name.push(' ');
bin_name.push_str(sc.get_name());
};
}

sc
};
sc = sc.bin_name(bin_name);

let parser = Parser::new(&mut sc);

Err(parser.help_err(true, Stream::Stdout))
Expand Down
2 changes: 1 addition & 1 deletion tests/builder/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ fn parent_cmd_req_in_usage_with_help_subcommand() {
some
USAGE:
parent test
parent <TARGET> <ARGS> test
OPTIONS:
-h, --help Print help information
Expand Down

0 comments on commit 1452c1e

Please sign in to comment.