-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(mangen): Support flatten_help #5769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
4823360 to
09f42dc
Compare
3f70e85 to
c2c7c26
Compare
5094ea2 to
77e56f6
Compare
|
|
7acd84c to
52a7a4c
Compare
|
@epage hey Ed I covered your comments as good as I could and think this is ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Differences between flattened
--helpand the flattened man:
--helpprints the description at the very beginning while Man uses a
section called DESCRIPTION below the USAGE.--helpprints placeholder[OPTIONS]while Man prints all options--helpprints positional options (aka arguments) in its own section
called arguments while Man prints them at the end of OPTIONS.--helpprints subcommands as their own section after the options
section while Man uses an extra section called SUBCOMMANDS--helpprintsafter_long_helpat the very end while Man uses the
section EXTRA which comes before the sections VERSION and AUTHORS
Most of these differences sound unrelated to flattening
26f3ad8 to
004e815
Compare
| #[test] | ||
| fn flatten_help_true() { | ||
| let name = "my-app"; | ||
| let cmd = common::basic_command(name).flatten_help(true); | ||
| common::assert_matches(snapbox::file!["../snapshots/flatten_help.roff"], cmd); | ||
| } | ||
|
|
||
| #[test] | ||
| fn flatten_help_true_subcommand_required_true() { | ||
| let name = "my-app"; | ||
| let cmd = common::basic_command(name) | ||
| .flatten_help(true) | ||
| .subcommand_required(true); | ||
| common::assert_matches( | ||
| snapbox::file!["../snapshots/flatten_help_subcommand_required.roff"], | ||
| cmd, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn flatten_help_true_subcommand_args_conflicts_with_subcommands() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests still needed with the addition of the --help tests?
c8d9c77 to
d5c2884
Compare
This test shows that the output stays the same independent of the value of `flatten_help`. Further commits may implement `flatten_help` for `clap_mangen`. Signed-off-by: Paul Spooren <mail@aparcar.org>
Add all tests from tests/builder/help.rs to mangen, too. Signed-off-by: Paul Spooren <mail@aparcar.org>
The function prints the usage of a (sub)command. Signed-off-by: Paul Spooren <mail@aparcar.org>
The `flatten_help` argument combines all subcommands on a single page. Until now this wasn't supported for `mangen`. With this command the sections `SYNOPSIS` as well as `SUBCOMMANDS` are changed to imitate the style of `git stash --help`. Differences between flattened `--help` and the flattened man: * `--help` prints the description at the very beginning while Man uses a section called DESCRIPTION below the USAGE. * `--help` prints placeholder `[OPTIONS]` while Man prints all options * `--help` prints positional options (aka arguments) in its own section called arguments while Man prints them at the end of OPTIONS. * `--help` prints subcommands as their own section after the options section while Man uses an extra section called SUBCOMMANDS * `--help` prints `after_long_help` at the very end while Man uses the section EXTRA which comes before the sections VERSION and AUTHORS Signed-off-by: Paul Spooren <mail@aparcar.org>
| if flatten { | ||
| let mut ord_v = Vec::new(); | ||
| for subcommand in cmd.get_subcommands() { | ||
| ord_v.push(( | ||
| subcommand.get_display_order(), | ||
| subcommand.get_bin_name().unwrap_or_else(|| cmd.get_name()), | ||
| subcommand, | ||
| )); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't recursive but should be (same with flat_subcommands)
|
I've cleaned up the commits and rebased but this is still lacking recursion, there is a question on whether tests are redundant, and the PR description seems to be describing more than just flattening. |
epage
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #5769 (comment)


The
flatten_helpargument combines all subcommands on a single page. Until now this wasn't supported formangen. With this command the sectionsSYNOPSISas well as(SUB)COMMANDSare changed to imitate the style ofgit stash --help.I reached out via discussions and it looks like this doesn't work just yet #5761
This is not necessarily the most beautiful implementation due to my limited knowledge of both
clapand Rust itself.I implemented this for a project I'm working on and the results look quite okay:
Not using
man.render()but call each command manually feels a bit awkward but does work just fine, see example here https://github.com/rosenpass/rosenpass/pull/434/files#diff-352422e105afd3138a54ea14e33af782243398f1d768d271655729dd4bcb99d2R18