-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Help message output is not sorted by option name #4728
Comments
This was stale documentation. In clap v3 we sorted arguments and commands but in v4 we switched exclusively to what we had called the derive display order. This provides a more WYSIWYG experience in writing help and was a very popular setting. As users can get a sorted order manually (or by writing code to manually sort), we felt that keeping this configurable did not carry enough weight as we looked to simplify the API. |
Hi, does this also affect the builder-pattern style? I just noticed that an application I recently updated to clap v4 also has the same new behaviour, despite the latest documentation claiming: let m = Command::new("prog")
.arg(Arg::new("a") // Typically args are grouped alphabetically by name.
// Args without a display_order have a value of 999 and are
// displayed alphabetically with all other 999 valued args. |
I must have been moving too fast with 6e1e754 as it changed the wrong part of the text when really the whole thing needed an overhaul. So this correctly fixed clap-rs#4728
Please complete the following tasks
Rust Version
rustc 1.69.0-nightly (07c993eba 2023-02-23)
Clap Version
4.1.6
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
I get this output:
That is, the arguments are not in alphabetical order as expected based on the documentation in
Arg::display_order
.Expected Behaviour
I would prefer help output to be sorted in alphabetical (or ASCII-betical) order as per previous
clap
versions.Additional Context
This appears to be the same bug as #2059.
Experimentation indicates that the help options are sorted first by
display_order
(which I have left at the default of 999 except when exploring this bug) and then by the order they appear in the structs.I have no strong opinion as to whether they should be sorted by the long option name, short option name, struct field name, or some heuristic based on all of them, but the current behaviour is not great. The workaround of manually sorting the struct fields does not work if one is using
#[clap(flatten)]
.Debug Output
The text was updated successfully, but these errors were encountered: