-
-
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(Opts and Flags): adds support for custom ordering in help messages
Allows custom ordering of args within the help message. Args with a lower value will be displayed first in the help message. This is helpful when one would like to emphasise frequently used args, or prioritize those towards the top of the list. Duplicate values **are** allowed. Args with duplicate display orders will be displayed in alphabetical order. **NOTE:** The default is 999 for all arguments. **NOTE:** This setting is ignored for positional arguments which are always displayed in index order. ```rust use clap::{App, Arg}; let m = App::new("cust-ord") .arg(Arg::with_name("a") // typically args are grouped by alphabetically by name // Args without a display_order have a value of 999 and are // displayed alphabetically with all other 999 args .long("long-option") .short("o") .takes_value(true) .help("Some help and text")) .arg(Arg::with_name("b") .long("other-option") .short("O") .takes_value(true) .display_order(1) // Let's force this arg to appear *first* // all we have to do is give it a value lower than 999 // any other args with a value of 1 would be displayed // alphabetically with other 1 args. Then 2, then 3, etc. .help("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 OPTIONS: -O, --other-option <b> I should be first! -o, --long-option <a> Some help and text ```
- Loading branch information
Showing
5 changed files
with
102 additions
and
18 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
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