Skip to content

Commit 69e8aad

Browse files
committed
Correctly handle forced clap's "help" command
1 parent 8d1178e commit 69e8aad

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/args.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ pub fn parse_from_argv<I, T>(argv: I) -> Result<Options, ArgsError>
4242
.find(|arg| !arg.starts_with("-"));
4343

4444
// (That is, provided we got a positional argument at all).
45-
if let Some(first_arg) = maybe_first_arg {
45+
let first_arg = maybe_first_arg.unwrap_or_else(|| "help".into());
46+
if first_arg != "help" {
4647
match Command::from_str(&first_arg) {
4748
Ok(_) => create_full_parser(),
4849
Err(_) => {
@@ -54,7 +55,7 @@ pub fn parse_from_argv<I, T>(argv: I) -> Result<Options, ArgsError>
5455
},
5556
}
5657
} else {
57-
// If we only got flag arguments, use the full parser (with subcommands).
58+
// If help was requested, use the full parser (with subcommands).
5859
// This ensure the correct help/usage instructions are shown.
5960
create_full_parser()
6061
}
@@ -422,6 +423,7 @@ fn create_parser_base<'p>() -> Parser<'p> {
422423
fn subcommand_for<'p>(command: Command) -> Parser<'p> {
423424
SubCommand::with_name(command.name())
424425
.visible_aliases(command.aliases())
426+
.help_short("H")
425427
}
426428

427429
/// Configure a parser for the "run" command.

0 commit comments

Comments
 (0)