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.

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

#[test]
fn configured_subcmd_order() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add all new tests in the first commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like all of the commits had been squashed. What you did with the test commit before the main commit was right, just more tests had been added in the "fixup".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, I misunderstood then. I've now split the commit into everything test related and then the fix itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the the commits should still be atomic, including each commit passing tests. The first commit should pass, showing the current behavior. The second commit should still pass, showing the new behavior.

The intent with this split is to

  1. Verify the tests test the right behavior by seeing them change
  2. Provide a visual demonstration of what this PR accomplishes by the diff between the two commits

@thomas-zahner thomas-zahner force-pushed the respect-display-order branch 6 times, most recently from 36cc073 to cbeb0ba Compare October 15, 2025 19:12
Eric Gumba added 2 commits October 15, 2025 21:22
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.
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