Skip to content

Conversation

@thomas-zahner
Copy link
Contributor

@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.

@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

@thomas-zahner thomas-zahner force-pushed the respect-display-order branch 2 times, most recently from 456552a to 3838990 Compare October 10, 2025 14:09
@thomas-zahner thomas-zahner force-pushed the respect-display-order branch 7 times, most recently from cbeb0ba to 1f07ad2 Compare October 15, 2025 19:23
thomas-zahner and others added 2 commits October 22, 2025 09:56
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.

Co-authored-by: ericgumba <[email protected]>
@epage
Copy link
Member

epage commented Oct 22, 2025

Thanks!

@epage epage merged commit 419244b into clap-rs:master Oct 22, 2025
25 checks passed
@thomas-zahner
Copy link
Contributor Author

Glad that I could help. Note that #6072 can now be closed

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