Skip to content

Conversation

thomas-zahner
Copy link

@thomas-zahner thomas-zahner commented Sep 26, 2025

This is branched off #6072 and fixes #3362. The work over at #6072 seems to have stalled. With this PR, I'd like to get the feature ready and merged.

My changes (see last commit) should resolve the comments left on the original PR. Additionally, I noticed that option_sort_key was fully copy/pasted on the original PR. I tried to reuse the logic and ended up creating ArgOrder. Not fully sure if this is the way to go, but I think it's quite a bit better than the current state. Especially the bit with the BTreeMap was unnecessary and positional_sort_key was a overly complicated way of saying "don't do anything".

Maybe you would like to implement or nameArgOrder differently? Also I'm not sure where I should place ArgOrder in order to be usable in both places.

Eric Gumba and others added 4 commits July 19, 2025 00:53
In clap-rs#3362 we have an issue where when we configure an arg via
.display_order(int), and then generate a manpage,
the synposis and options will render the order the args were
provided to the App rather than the order they were configured

e.g

Command::new(name)
arg(Arg::new("few").short('b').display_order(2))
arg(Arg::new("bar").short('a').display_order(1))

will show

...
SYNOPSIS
    <name> [-b] [-a] ...

...
OPTIONS
    -b
    -a

instead of

...
SYNOPSIS
    <name> [-a] [-b] ...

...
OPTIONS
    -a
    -b

and so on. This fix adds sorting in the synopsis and
options functions responsible for generating the
corresponding synopsis and options sections of the manpage.
1. Reused sorting method in help_template.rs.

2. More thorough testing of configured ordering, instead of
relying solely on snapbox.

3. Added sorting to subcommand section of clap_mangen
@epage
Copy link
Member

epage commented Sep 26, 2025

Likely won't get to this until Monday but a couple of notes

  • I prefer a clean, logical commit history, finding it easier to review. I'd prefer fixups to be squashed into their respective commits
  • I'm not ready for us to expose something like ArgOrder and would prefer copy/paste. The whole existence of clap_mangen is a community driven hack until we work to refactor our help generation to allow reuse we intend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clap_man should respect the configured display order for args and subcommands
2 participants