Skip to content

Commit

Permalink
Fix help text display for sub-commands
Browse files Browse the repository at this point in the history
The logic we added for displaying extensions in the program's help text
turned out to be faulty when the user asked for the help to a
sub-command. Evidently, the display of such a sub-command help text is
covered by the same error kind, but it is wrong to simply display the
program help text unconditionally.
With this change we fix this state of affairs by re-triggering the
program parsing on the custom crafted command object, which will ensure
that the correct help text is printed on error.
  • Loading branch information
d-e-s-o committed Feb 21, 2024
1 parent 258e60b commit dfad641
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,17 @@ async fn run() -> Result<()> {
.about(about as &'static str),
);
}
let () = clap.print_help()?;

// Note that this path may be invoked on paths that ultimately
// do *not* display the program help (but rather that of a
// subcommand). As such, just invoking `clap.print_help()`
// will *not* do the right thing. Instead, re-parse arguments
// here again.
// SANITY: We parsed the same program arguments above and
// err'd out. We assume we do the same thing here
// again, as nothing of relevance has changed.
let err = clap.try_get_matches_from(args_os()).unwrap_err();
print!("{}", err);
}
return Ok(())
},
Expand Down

0 comments on commit dfad641

Please sign in to comment.