-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Subcommands): adds support for custom ordering in help messages
Allows custom ordering of subcommands within the help message. Subcommands with a lower value will be displayed first in the help message. This is helpful when one would like to emphasise frequently used subcommands, or prioritize those towards the top of the list. Duplicate values **are** allowed. Subcommands with duplicate display orders will be displayed in alphabetical order. **NOTE:** The default is 999 for all subcommands. ```rust use clap::{App, SubCommand}; let m = App::new("cust-ord") .subcommand(SubCommand::with_name("alpha") // typically subcommands are grouped // alphabetically by name. Subcommands // without a display_order have a value of // 999 and are displayed alphabetically with // all other 999 subcommands .about("Some help and text")) .subcommand(SubCommand::with_name("beta") .display_order(1) // In order to force this subcommand to appear *first* // all we have to do is give it a value lower than 999. // Any other subcommands with a value of 1 will be displayed // alphabetically with this one...then 2 values, then 3, etc. .about("I should be first!")) .get_matches_from(vec![ "cust-ord", "--help" ]); ``` The above example displays the following help message ``` cust-ord USAGE: cust-ord [FLAGS] [OPTIONS] FLAGS: -h, --help Prints help information -V, --version Prints version information SUBCOMMANDS: beta I should be first! alpha Some help and text ``` Closes #442
- Loading branch information
Showing
3 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters