Skip to content

Conversation

ericgumba
Copy link

In #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
[-b] [-a] ...

...
OPTIONS
-b
-a

instead of

...
SYNOPSIS
[-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.

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.
Copy link
Member

@pksunkara pksunkara left a comment

Choose a reason for hiding this comment

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

I don't see any issue here. Unless @epage wants to do this with shell completions too in this PR.

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
@@ -1,6 +1,26 @@
use clap::{Arg, ArgAction};
use roff::{bold, italic, roman, Inline, Roff};

pub(crate) fn option_sort_key(arg: &Arg) -> (usize, String) {
Copy link
Member

Choose a reason for hiding this comment

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

This should be at the bottom of the file, not the top, so people start with the entry points that matter and dig into details as needed

@@ -1,6 +1,26 @@
use clap::{Arg, ArgAction};
use roff::{bold, italic, roman, Inline, Roff};

pub(crate) fn option_sort_key(arg: &Arg) -> (usize, String) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look like it needs to be pub(crate)

@epage
Copy link
Member

epage commented Jul 29, 2025

Please clean up the commits for how they should be merged

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.

3 participants