mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
Merge pull request #3975 from epage/ord
fix(help)!: Make DeriveDisplayOrder the default, removing it
This commit is contained in:
commit
f47c361cdb
52 changed files with 1096 additions and 1537 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
### Breaking Changes
|
||||
|
||||
- `ErrorKind::EmptyValue` replaced with `ErrorKind::InvalidValue`
|
||||
- `ErrorKind::UnrecognizedSubcommand` replaced with `ErrorKind::InvalidSubcommand`
|
||||
- `arg!` now sets `ArgAction::SetTrue`, `ArgAction::Count`, `ArgAction::Set`, or `ArgAction::Append` as appropriate
|
||||
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag
|
||||
- *(derive)* `subcommand_required(true).arg_required_else_help(true)` is set instead of `SubcommandRequiredElseHelp`
|
||||
- `ErrorKind::UnrecognizedSubcommand` replaced with `ErrorKind::InvalidSubcommand` (#3676)
|
||||
- `arg!` now sets `ArgAction::SetTrue`, `ArgAction::Count`, `ArgAction::Set`, or `ArgAction::Append` as appropriate (#3795)
|
||||
- *(help)* Make `DeriveDisplayOrder` the default and removed the setting. To sort help, set `next_display_order(None)` (#2808)
|
||||
- *(help)* Subcommand display order respects `Command::next_display_order` instead of `DeriveDisplayOrder` and using its own initial display order value (#2808)
|
||||
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag (#3776)
|
||||
- *(derive)* `subcommand_required(true).arg_required_else_help(true)` is set instead of `SubcommandRequiredElseHelp` (#3280)
|
||||
|
||||
### Features
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// CLI used is from rustup 408ed84f0e50511ed44a405dd91365e5da588790
|
||||
|
||||
use clap::{AppSettings, Arg, ArgGroup, Command};
|
||||
use clap::{Arg, ArgGroup, Command};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
pub fn build_rustup(c: &mut Criterion) {
|
||||
|
@ -26,7 +26,6 @@ fn build_cli() -> Command<'static> {
|
|||
.version("0.9.0") // Simulating
|
||||
.about("The Rust toolchain installer")
|
||||
.after_help(RUSTUP_HELP)
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.help("Enable verbose output")
|
||||
|
@ -67,7 +66,6 @@ fn build_cli() -> Command<'static> {
|
|||
Command::new("toolchain")
|
||||
.about("Modify or query the installed toolchains")
|
||||
.after_help(TOOLCHAIN_HELP)
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(Command::new("list").about("List installed toolchains"))
|
||||
.subcommand(
|
||||
Command::new("install")
|
||||
|
@ -104,7 +102,6 @@ fn build_cli() -> Command<'static> {
|
|||
.subcommand(
|
||||
Command::new("target")
|
||||
.about("Modify a toolchain's supported targets")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(
|
||||
Command::new("list")
|
||||
.about("List installed and available targets")
|
||||
|
@ -138,7 +135,6 @@ fn build_cli() -> Command<'static> {
|
|||
.subcommand(
|
||||
Command::new("component")
|
||||
.about("Modify a toolchain's installed components")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(
|
||||
Command::new("list")
|
||||
.about("List installed and available components")
|
||||
|
@ -163,7 +159,6 @@ fn build_cli() -> Command<'static> {
|
|||
Command::new("override")
|
||||
.about("Modify directory toolchain overrides")
|
||||
.after_help(OVERRIDE_HELP)
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(Command::new("list").about("List directory toolchain overrides"))
|
||||
.subcommand(
|
||||
Command::new("set")
|
||||
|
@ -246,7 +241,6 @@ fn build_cli() -> Command<'static> {
|
|||
.subcommand(
|
||||
Command::new("self")
|
||||
.about("Modify the rustup installation")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(Command::new("update").about("Download and install updates to rustup"))
|
||||
.subcommand(
|
||||
Command::new("uninstall")
|
||||
|
@ -261,7 +255,6 @@ fn build_cli() -> Command<'static> {
|
|||
Command::new("telemetry")
|
||||
.about("rustup telemetry commands")
|
||||
.hide(true)
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(Command::new("enable").about("Enable rustup telemetry"))
|
||||
.subcommand(Command::new("disable").about("Disable rustup telemetry"))
|
||||
.subcommand(Command::new("analyze").about("Analyze stored telemetry")),
|
||||
|
|
|
@ -62,7 +62,7 @@ pub fn subcommands(p: &Command) -> Vec<(String, String)> {
|
|||
}
|
||||
|
||||
/// Gets all the short options, their visible aliases and flags of a [`clap::Command`].
|
||||
/// Includes `h` and `V` depending on the [`clap::AppSettings`].
|
||||
/// Includes `h` and `V` depending on the [`clap::Command`] settings.
|
||||
pub fn shorts_and_visible_aliases(p: &Command) -> Vec<char> {
|
||||
debug!("shorts: name={}", p.get_name());
|
||||
|
||||
|
@ -87,7 +87,7 @@ pub fn shorts_and_visible_aliases(p: &Command) -> Vec<char> {
|
|||
}
|
||||
|
||||
/// Gets all the long options, their visible aliases and flags of a [`clap::Command`].
|
||||
/// Includes `help` and `version` depending on the [`clap::AppSettings`].
|
||||
/// Includes `help` and `version` depending on the [`clap::Command`] settings.
|
||||
pub fn longs_and_visible_aliases(p: &Command) -> Vec<String> {
|
||||
debug!("longs: name={}", p.get_name());
|
||||
|
||||
|
@ -117,7 +117,7 @@ pub fn longs_and_visible_aliases(p: &Command) -> Vec<String> {
|
|||
}
|
||||
|
||||
/// Gets all the flags of a [`clap::Command`](Command).
|
||||
/// Includes `help` and `version` depending on the [`clap::AppSettings`].
|
||||
/// Includes `help` and `version` depending on the [`clap::Command`] settings.
|
||||
pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
|
||||
debug!("flags: name={}", p.get_name());
|
||||
p.get_arguments()
|
||||
|
|
|
@ -26,8 +26,8 @@ USAGE:
|
|||
cargo example-derive [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--manifest-path <MANIFEST_PATH>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
```
|
||||
|
|
|
@ -26,8 +26,8 @@ USAGE:
|
|||
cargo example [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--manifest-path <PATH>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
```
|
||||
|
|
|
@ -7,9 +7,9 @@ USAGE:
|
|||
demo[EXE] [OPTIONS] --name <NAME>
|
||||
|
||||
OPTIONS:
|
||||
-n, --name <NAME> Name of the person to greet
|
||||
-c, --count <COUNT> Number of times to greet [default: 1]
|
||||
-h, --help Print help information
|
||||
-n, --name <NAME> Name of the person to greet
|
||||
-V, --version Print version information
|
||||
|
||||
$ demo --name Me
|
||||
|
|
|
@ -14,8 +14,8 @@ ARGS:
|
|||
<BOOM> [possible values: true, false]
|
||||
|
||||
OPTIONS:
|
||||
--bar <BAR> [default: false]
|
||||
--foo <FOO> [possible values: true, false]
|
||||
--bar <BAR> [default: false]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
|
|
|
@ -107,13 +107,13 @@ USAGE:
|
|||
interop_hand_subcommand[EXE] [OPTIONS] <SUBCOMMAND>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-t, --top-level
|
||||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
add
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
remove
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
```
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ ARGS:
|
|||
|
||||
OPTIONS:
|
||||
-f
|
||||
-h, --help Print help information
|
||||
-p <PEAR>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
```
|
||||
|
|
|
@ -16,8 +16,8 @@ ARGS:
|
|||
|
||||
OPTIONS:
|
||||
-f
|
||||
-h, --help Print help information
|
||||
-p <PEAR>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
```
|
||||
|
|
|
@ -16,11 +16,11 @@ OPTIONS:
|
|||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
add adds things
|
||||
clone Clones repos
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
push pushes things
|
||||
add adds things
|
||||
stash
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
$ git-derive help
|
||||
git
|
||||
|
@ -33,11 +33,11 @@ OPTIONS:
|
|||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
add adds things
|
||||
clone Clones repos
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
push pushes things
|
||||
add adds things
|
||||
stash
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
$ git-derive help add
|
||||
git-add
|
||||
|
@ -85,14 +85,14 @@ USAGE:
|
|||
git-derive[EXE] stash <SUBCOMMAND>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-m, --message <MESSAGE>
|
||||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
push
|
||||
pop
|
||||
apply
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
pop
|
||||
push
|
||||
|
||||
$ git-derive stash push -h
|
||||
git-stash-push
|
||||
|
@ -101,8 +101,8 @@ USAGE:
|
|||
git-derive[EXE] stash push [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-m, --message <MESSAGE>
|
||||
-h, --help Print help information
|
||||
|
||||
$ git-derive stash pop -h
|
||||
git-stash-pop
|
||||
|
|
|
@ -14,11 +14,11 @@ OPTIONS:
|
|||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
add adds things
|
||||
clone Clones repos
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
push pushes things
|
||||
add adds things
|
||||
stash
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
$ git help
|
||||
git
|
||||
|
@ -31,11 +31,11 @@ OPTIONS:
|
|||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
add adds things
|
||||
clone Clones repos
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
push pushes things
|
||||
add adds things
|
||||
stash
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
$ git help add
|
||||
git-add
|
||||
|
@ -83,14 +83,14 @@ USAGE:
|
|||
git[EXE] stash <SUBCOMMAND>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-m, --message <MESSAGE>
|
||||
-h, --help Print help information
|
||||
|
||||
SUBCOMMANDS:
|
||||
push
|
||||
pop
|
||||
apply
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
pop
|
||||
push
|
||||
|
||||
$ git stash push -h
|
||||
git-stash-push
|
||||
|
@ -99,8 +99,8 @@ USAGE:
|
|||
git[EXE] stash push [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-m, --message <MESSAGE>
|
||||
-h, --help Print help information
|
||||
|
||||
$ git stash pop -h
|
||||
git-stash-pop
|
||||
|
|
|
@ -31,12 +31,12 @@ USAGE:
|
|||
busybox [OPTIONS] [APPLET]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--install <install> Install hardlinks for all subcommands in path
|
||||
-h, --help Print help information
|
||||
|
||||
APPLETS:
|
||||
true does nothing successfully
|
||||
false does nothing unsuccessfully
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
true does nothing successfully
|
||||
|
||||
```
|
||||
|
|
|
@ -47,9 +47,9 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
query -Q --query Query the package database.
|
||||
sync -S --sync Synchronize packages.
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
$ pacman -S -h
|
||||
pacman-sync
|
||||
|
@ -62,9 +62,9 @@ ARGS:
|
|||
<package>... packages
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-i, --info view package information
|
||||
-s, --search <search>... search remote repositories for matching strings
|
||||
-i, --info view package information
|
||||
-h, --help Print help information
|
||||
|
||||
```
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test does testing things
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
```
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use clap::{arg, command, AppSettings, ArgAction};
|
||||
use clap::{arg, command, ArgAction};
|
||||
|
||||
fn main() {
|
||||
let matches = command!() // requires `cargo` feature
|
||||
.global_setting(AppSettings::DeriveDisplayOrder)
|
||||
.allow_negative_numbers(true)
|
||||
.arg(arg!(--two <VALUE>).action(ArgAction::Set))
|
||||
.arg(arg!(--one <VALUE>).action(ArgAction::Set))
|
||||
|
|
|
@ -8,9 +8,9 @@ USAGE:
|
|||
02_apps[EXE] --two <VALUE> --one <VALUE>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--one <VALUE>
|
||||
--two <VALUE>
|
||||
--one <VALUE>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 02_apps --version
|
||||
|
|
|
@ -7,9 +7,9 @@ USAGE:
|
|||
02_crate[EXE] --two <VALUE> --one <VALUE>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--one <VALUE>
|
||||
--two <VALUE>
|
||||
--one <VALUE>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 02_crate --version
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_01_flag_bool[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-v, --verbose
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_01_flag_bool
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_01_flag_count[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-v, --verbose
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_01_flag_count
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_02_option[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-n, --name <NAME>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_02_option
|
||||
|
|
|
@ -10,13 +10,13 @@ ARGS:
|
|||
<INPUT_FILE> some regular input
|
||||
|
||||
OPTIONS:
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
--set-ver <VER> set version manually
|
||||
--major auto inc major
|
||||
--minor auto inc minor
|
||||
--patch auto inc patch
|
||||
--set-ver <VER> set version manually
|
||||
--spec-in <SPEC_IN> some special input argument
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 04_03_relations
|
||||
|
|
|
@ -10,13 +10,13 @@ ARGS:
|
|||
<INPUT_FILE> some regular input
|
||||
|
||||
OPTIONS:
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
--set-ver <VER> set version manually
|
||||
--major auto inc major
|
||||
--minor auto inc minor
|
||||
--patch auto inc patch
|
||||
--set-ver <VER> set version manually
|
||||
--spec-in <SPEC_IN> some special input argument
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 04_04_custom
|
||||
|
|
|
@ -16,8 +16,8 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test does testing things
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
```
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use clap::{AppSettings, Parser};
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
#[clap(allow_negative_numbers = true)]
|
||||
#[clap(global_setting(AppSettings::DeriveDisplayOrder))]
|
||||
struct Cli {
|
||||
#[clap(long, value_parser)]
|
||||
two: String,
|
||||
|
|
|
@ -8,9 +8,9 @@ USAGE:
|
|||
02_apps[EXE] --two <VALUE> --one <VALUE>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--one <VALUE>
|
||||
--two <VALUE>
|
||||
--one <VALUE>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 02_apps --version
|
||||
|
|
|
@ -7,9 +7,9 @@ USAGE:
|
|||
02_crate[EXE] --two <VALUE> --one <VALUE>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
--one <VALUE>
|
||||
--two <VALUE>
|
||||
--one <VALUE>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 02_crate --version
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_01_flag_bool[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-v, --verbose
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_01_flag_bool
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_01_flag_count[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-v, --verbose
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_01_flag_count
|
||||
|
|
|
@ -7,8 +7,8 @@ USAGE:
|
|||
03_02_option[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-n, --name <NAME>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 03_02_option
|
||||
|
|
|
@ -10,13 +10,13 @@ ARGS:
|
|||
<INPUT_FILE> some regular input
|
||||
|
||||
OPTIONS:
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
--set-ver <VER> set version manually
|
||||
--major auto inc major
|
||||
--minor auto inc minor
|
||||
--patch auto inc patch
|
||||
--set-ver <VER> set version manually
|
||||
--spec-in <SPEC_IN> some special input argument
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 04_03_relations
|
||||
|
|
|
@ -10,13 +10,13 @@ ARGS:
|
|||
<INPUT_FILE> some regular input
|
||||
|
||||
OPTIONS:
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
--set-ver <VER> set version manually
|
||||
--major auto inc major
|
||||
--minor auto inc minor
|
||||
--patch auto inc patch
|
||||
--set-ver <VER> set version manually
|
||||
--spec-in <SPEC_IN> some special input argument
|
||||
-c <CONFIG>
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
$ 04_04_custom
|
||||
|
|
|
@ -9,12 +9,12 @@ USAGE:
|
|||
typed-derive[EXE] [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-O <OPTIMIZATION> Implicitly using `std::str::FromStr`
|
||||
-I <DIR> Allow invalid UTF-8 paths
|
||||
--bind <BIND> Handle IP addresses
|
||||
--sleep <SLEEP> Allow human-readable durations
|
||||
-D <DEFINES> Hand-written parser for tuples
|
||||
-h, --help Print help information
|
||||
-I <DIR> Allow invalid UTF-8 paths
|
||||
-O <OPTIMIZATION> Implicitly using `std::str::FromStr`
|
||||
--sleep <SLEEP> Allow human-readable durations
|
||||
|
||||
```
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use bitflags::bitflags;
|
|||
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct AppFlags(Flags);
|
||||
pub(crate) struct AppFlags(Flags);
|
||||
|
||||
impl Default for AppFlags {
|
||||
fn default() -> Self {
|
||||
|
@ -29,347 +29,41 @@ impl Default for AppFlags {
|
|||
/// [`Command`]: crate::Command
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum AppSettings {
|
||||
/// Deprecated, replaced with [`Command::ignore_errors`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "Replaced with `Command::ignore_errors`")
|
||||
)]
|
||||
pub(crate) enum AppSettings {
|
||||
IgnoreErrors,
|
||||
|
||||
/// Deprecated, replaced with [`Command::allow_hyphen_values`] and
|
||||
/// [`Arg::is_allow_hyphen_values_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::allow_hyphen_values` and `Arg::is_allow_hyphen_values_set`"
|
||||
)
|
||||
)]
|
||||
AllowHyphenValues,
|
||||
|
||||
/// Deprecated, replaced with [`Command::allow_negative_numbers`] and
|
||||
/// [`Command::is_allow_negative_numbers_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::allow_negative_numbers` and `Command::is_allow_negative_numbers_set`"
|
||||
)
|
||||
)]
|
||||
AllowNegativeNumbers,
|
||||
|
||||
/// Deprecated, replaced with [`Command::allow_missing_positional`] and
|
||||
/// [`Command::is_allow_missing_positional_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::allow_missing_positional` and `Command::is_allow_missing_positional_set`"
|
||||
)
|
||||
)]
|
||||
AllowMissingPositional,
|
||||
|
||||
/// Deprecated, replaced with [`Command::trailing_var_arg`] and [`Command::is_trailing_var_arg_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::trailing_var_arg` and `Command::is_trailing_var_arg_set`"
|
||||
)
|
||||
)]
|
||||
TrailingVarArg,
|
||||
|
||||
/// Deprecated, replaced with [`Command::dont_delimit_trailing_values`] and
|
||||
/// [`Command::is_dont_delimit_trailing_values_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::dont_delimit_trailing_values` and `Command::is_dont_delimit_trailing_values_set`"
|
||||
)
|
||||
)]
|
||||
DontDelimitTrailingValues,
|
||||
|
||||
/// Deprecated, replaced with [`Command::infer_long_args`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "Replaced with `Command::infer_long_args`")
|
||||
)]
|
||||
InferLongArgs,
|
||||
|
||||
/// Deprecated, replaced with [`Command::infer_subcommands`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "Replaced with `Command::infer_subcommands`")
|
||||
)]
|
||||
InferSubcommands,
|
||||
|
||||
/// Deprecated, replaced with [`Command::subcommand_required`] and
|
||||
/// [`Command::is_subcommand_required_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::subcommand_required` and `Command::is_subcommand_required_set`"
|
||||
)
|
||||
)]
|
||||
SubcommandRequired,
|
||||
|
||||
/// Deprecated, replaced with [`Command::allow_external_subcommands`] and
|
||||
/// [`Command::is_allow_external_subcommands_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::allow_external_subcommands` and `Command::is_allow_external_subcommands_set`"
|
||||
)
|
||||
)]
|
||||
AllowExternalSubcommands,
|
||||
|
||||
/// Deprecated, replaced with [`Command::multicall`] and [`Command::is_multicall_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::multicall` and `Command::is_multicall_set`"
|
||||
)
|
||||
)]
|
||||
Multicall,
|
||||
|
||||
/// Deprecated, replaced with [`Command::allow_invalid_utf8_for_external_subcommands`] and [`Command::is_allow_invalid_utf8_for_external_subcommands_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::allow_invalid_utf8_for_external_subcommands` and `Command::is_allow_invalid_utf8_for_external_subcommands_set`"
|
||||
)
|
||||
)]
|
||||
AllowInvalidUtf8ForExternalSubcommands,
|
||||
|
||||
/// Deprecated, this is now the default
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "This is now the default")
|
||||
)]
|
||||
UseLongFormatForHelpSubcommand,
|
||||
|
||||
/// Deprecated, replaced with [`Command::subcommand_negates_reqs`] and
|
||||
/// [`Command::is_subcommand_negates_reqs_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::subcommand_negates_reqs` and `Command::is_subcommand_negates_reqs_set`"
|
||||
)
|
||||
)]
|
||||
SubcommandsNegateReqs,
|
||||
|
||||
/// Deprecated, replaced with [`Command::args_conflicts_with_subcommands`] and
|
||||
/// [`Command::is_args_conflicts_with_subcommands_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::args_conflicts_with_subcommands` and `Command::is_args_conflicts_with_subcommands_set`"
|
||||
)
|
||||
)]
|
||||
ArgsNegateSubcommands,
|
||||
|
||||
/// Deprecated, replaced with [`Command::subcommand_precedence_over_arg`] and
|
||||
/// [`Command::is_subcommand_precedence_over_arg_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::subcommand_precedence_over_arg` and `Command::is_subcommand_precedence_over_arg_set`"
|
||||
)
|
||||
)]
|
||||
SubcommandPrecedenceOverArg,
|
||||
|
||||
/// Deprecated, replaced with [`Command::arg_required_else_help`] and
|
||||
/// [`Command::is_arg_required_else_help_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::arg_required_else_help` and `Command::is_arg_required_else_help_set`"
|
||||
)
|
||||
)]
|
||||
ArgRequiredElseHelp,
|
||||
|
||||
/// Displays the arguments and [`subcommands`] in the help message in the order that they were
|
||||
/// declared in, and not alphabetically which is the default.
|
||||
///
|
||||
/// To override the declaration order, see [`Arg::display_order`] and [`Command::display_order`].
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, Arg, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .global_setting(AppSettings::DeriveDisplayOrder)
|
||||
/// .get_matches();
|
||||
/// ```
|
||||
///
|
||||
/// [`subcommands`]: crate::Command::subcommand()
|
||||
/// [`Arg::display_order`]: crate::Arg::display_order
|
||||
/// [`Command::display_order`]: crate::Command::display_order
|
||||
DeriveDisplayOrder,
|
||||
|
||||
/// Deprecated, replaced with [`Command::dont_collapse_args_in_usage`] and
|
||||
/// [`Command::is_dont_collapse_args_in_usage_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::dont_collapse_args_in_usage` and `Command::is_dont_collapse_args_in_usage_set`"
|
||||
)
|
||||
)]
|
||||
DontCollapseArgsInUsage,
|
||||
|
||||
/// Deprecated, replaced with [`Command::next_line_help`] and [`Command::is_next_line_help_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::next_line_help` and `Command::is_next_line_help_set`"
|
||||
)
|
||||
)]
|
||||
NextLineHelp,
|
||||
|
||||
/// Deprecated, replaced with [`Command::disable_colored_help`] and
|
||||
/// [`Command::is_disable_colored_help_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::disable_colored_help` and `Command::is_disable_colored_help_set`"
|
||||
)
|
||||
)]
|
||||
DisableColoredHelp,
|
||||
|
||||
/// Deprecated, replaced with [`Command::disable_help_flag`] and [`Command::is_disable_help_flag_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::disable_help_flag` and `Command::is_disable_help_flag_set`"
|
||||
)
|
||||
)]
|
||||
DisableHelpFlag,
|
||||
|
||||
/// Deprecated, replaced with [`Command::disable_help_subcommand`] and
|
||||
/// [`Command::is_disable_help_subcommand_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::disable_help_subcommand` and `Command::is_disable_help_subcommand_set`"
|
||||
)
|
||||
)]
|
||||
DisableHelpSubcommand,
|
||||
|
||||
/// Deprecated, replaced with [`Command::disable_version_flag`] and
|
||||
/// [`Command::is_disable_version_flag_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::disable_version_flag` and `Command::is_disable_version_flag_set`"
|
||||
)
|
||||
)]
|
||||
DisableVersionFlag,
|
||||
|
||||
/// Deprecated, replaced with [`Command::propagate_version`] and [`Command::is_propagate_version_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::propagate_version` and `Command::is_propagate_version_set`"
|
||||
)
|
||||
)]
|
||||
PropagateVersion,
|
||||
|
||||
/// Deprecated, replaced with [`Command::hide`] and [`Command::is_hide_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::hide` and `Command::is_hide_set`"
|
||||
)
|
||||
)]
|
||||
Hidden,
|
||||
|
||||
/// Deprecated, replaced with [`Command::hide_possible_values`] and
|
||||
/// [`Arg::is_hide_possible_values_set`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(
|
||||
since = "3.1.0",
|
||||
note = "Replaced with `Command::hide_possible_values` and `Arg::is_hide_possible_values_set`"
|
||||
)
|
||||
)]
|
||||
HidePossibleValues,
|
||||
|
||||
/// Deprecated, replaced with [`Command::help_expected`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "Replaced with `Command::help_expected`")
|
||||
)]
|
||||
HelpExpected,
|
||||
|
||||
/// Deprecated, replaced with [`Command::no_binary_name`]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.1.0", note = "Replaced with `Command::no_binary_name`")
|
||||
)]
|
||||
NoBinaryName,
|
||||
|
||||
/// Deprecated, replaced with [`Arg::action`][super::Arg::action]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.2.0", note = "Replaced with `Arg::action`")
|
||||
)]
|
||||
NoAutoHelp,
|
||||
|
||||
/// Deprecated, replaced with [`Arg::action`][super::Arg::action]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.2.0", note = "Replaced with `Arg::action`")
|
||||
)]
|
||||
NoAutoVersion,
|
||||
|
||||
/// Deprecated, see [`Command::color`][crate::Command::color]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.0.0", note = "Replaced with `Command::color`")
|
||||
)]
|
||||
#[doc(hidden)]
|
||||
#[allow(dead_code)]
|
||||
ColorAuto,
|
||||
|
||||
/// Deprecated, replaced with [`Command::color`][crate::Command::color]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.0.0", note = "Replaced with `Command::color`")
|
||||
)]
|
||||
#[doc(hidden)]
|
||||
ColorAlways,
|
||||
|
||||
/// Deprecated, replaced with [`Command::color`][crate::Command::color]
|
||||
#[cfg_attr(
|
||||
feature = "deprecated",
|
||||
deprecated(since = "3.0.0", note = "Replaced with `Command::color`")
|
||||
)]
|
||||
#[doc(hidden)]
|
||||
ColorNever,
|
||||
|
||||
/// If the cmd is already built, used for caching.
|
||||
#[doc(hidden)]
|
||||
Built,
|
||||
|
||||
/// If the cmd's bin name is already built, used for caching.
|
||||
#[doc(hidden)]
|
||||
BinNameBuilt,
|
||||
}
|
||||
|
||||
|
@ -392,7 +86,6 @@ bitflags! {
|
|||
const LEADING_HYPHEN = 1 << 16;
|
||||
const NO_POS_VALUES = 1 << 17;
|
||||
const NEXT_LINE_HELP = 1 << 18;
|
||||
const DERIVE_DISP_ORDER = 1 << 19;
|
||||
const DISABLE_COLORED_HELP = 1 << 20;
|
||||
const COLOR_ALWAYS = 1 << 21;
|
||||
const COLOR_AUTO = 1 << 22;
|
||||
|
@ -413,7 +106,6 @@ bitflags! {
|
|||
const HELP_REQUIRED = 1 << 39;
|
||||
const SUBCOMMAND_PRECEDENCE_OVER_ARG = 1 << 40;
|
||||
const DISABLE_HELP_FLAG = 1 << 41;
|
||||
const USE_LONG_FORMAT_FOR_HELP_SC = 1 << 42;
|
||||
const INFER_LONG_ARGS = 1 << 43;
|
||||
const IGNORE_ERRORS = 1 << 44;
|
||||
const MULTICALL = 1 << 45;
|
||||
|
@ -448,8 +140,6 @@ impl_settings! { AppSettings, AppFlags,
|
|||
=> Flags::DONT_DELIM_TRAIL,
|
||||
DontCollapseArgsInUsage
|
||||
=> Flags::DONT_COLLAPSE_ARGS,
|
||||
DeriveDisplayOrder
|
||||
=> Flags::DERIVE_DISP_ORDER,
|
||||
DisableColoredHelp
|
||||
=> Flags::DISABLE_COLORED_HELP,
|
||||
DisableHelpSubcommand
|
||||
|
@ -478,8 +168,6 @@ impl_settings! { AppSettings, AppFlags,
|
|||
=> Flags::SC_NEGATE_REQS,
|
||||
SubcommandRequired
|
||||
=> Flags::SC_REQUIRED,
|
||||
UseLongFormatForHelpSubcommand
|
||||
=> Flags::USE_LONG_FORMAT_FOR_HELP_SC,
|
||||
TrailingVarArg
|
||||
=> Flags::TRAILING_VARARG,
|
||||
NextLineHelp
|
||||
|
|
|
@ -70,7 +70,7 @@ pub struct Arg<'help> {
|
|||
pub(crate) long: Option<&'help str>,
|
||||
pub(crate) aliases: Vec<(&'help str, bool)>, // (name, visible)
|
||||
pub(crate) short_aliases: Vec<(char, bool)>, // (name, visible)
|
||||
pub(crate) disp_ord: DisplayOrder,
|
||||
pub(crate) disp_ord: Option<usize>,
|
||||
pub(crate) val_names: Vec<&'help str>,
|
||||
pub(crate) num_vals: Option<usize>,
|
||||
pub(crate) max_vals: Option<usize>,
|
||||
|
@ -2411,7 +2411,7 @@ impl<'help> Arg<'help> {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
pub fn display_order(mut self, ord: usize) -> Self {
|
||||
self.disp_ord.set_explicit(ord);
|
||||
self.disp_ord = Some(ord);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -4478,7 +4478,7 @@ impl<'help> Arg<'help> {
|
|||
}
|
||||
|
||||
pub(crate) fn get_display_order(&self) -> usize {
|
||||
self.disp_ord.get_explicit()
|
||||
self.disp_ord.unwrap_or(999)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4675,43 +4675,6 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) enum DisplayOrder {
|
||||
None,
|
||||
Implicit(usize),
|
||||
Explicit(usize),
|
||||
}
|
||||
|
||||
impl DisplayOrder {
|
||||
pub(crate) fn set_explicit(&mut self, explicit: usize) {
|
||||
*self = Self::Explicit(explicit)
|
||||
}
|
||||
|
||||
pub(crate) fn set_implicit(&mut self, implicit: usize) {
|
||||
*self = (*self).max(Self::Implicit(implicit))
|
||||
}
|
||||
|
||||
pub(crate) fn make_explicit(&mut self) {
|
||||
match *self {
|
||||
Self::None | Self::Explicit(_) => {}
|
||||
Self::Implicit(disp) => self.set_explicit(disp),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_explicit(self) -> usize {
|
||||
match self {
|
||||
Self::None | Self::Implicit(_) => 999,
|
||||
Self::Explicit(disp) => disp,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DisplayOrder {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
// Flags
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
|
@ -176,7 +176,7 @@ impl<'help> Command<'help> {
|
|||
if let Some(current_disp_ord) = self.current_disp_ord.as_mut() {
|
||||
if !arg.is_positional() && arg.provider != ArgProvider::Generated {
|
||||
let current = *current_disp_ord;
|
||||
arg.disp_ord.set_implicit(current);
|
||||
arg.disp_ord.get_or_insert(current);
|
||||
*current_disp_ord = current + 1;
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +402,13 @@ impl<'help> Command<'help> {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
pub fn subcommand<S: Into<Self>>(mut self, subcmd: S) -> Self {
|
||||
self.subcommands.push(subcmd.into());
|
||||
let mut subcmd = subcmd.into();
|
||||
if let Some(current_disp_ord) = self.current_disp_ord.as_mut() {
|
||||
let current = *current_disp_ord;
|
||||
subcmd.disp_ord.get_or_insert(current);
|
||||
*current_disp_ord = current + 1;
|
||||
}
|
||||
self.subcommands.push(subcmd);
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -426,8 +432,12 @@ impl<'help> Command<'help> {
|
|||
I: IntoIterator<Item = T>,
|
||||
T: Into<Self>,
|
||||
{
|
||||
for subcmd in subcmds.into_iter() {
|
||||
self.subcommands.push(subcmd.into());
|
||||
let subcmds = subcmds.into_iter();
|
||||
let (lower, _) = subcmds.size_hint();
|
||||
self.subcommands.reserve(lower);
|
||||
|
||||
for subcmd in subcmds {
|
||||
self = self.subcommand(subcmd);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
@ -994,7 +1004,6 @@ impl<'help> Command<'help> {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
pub fn color(self, color: ColorChoice) -> Self {
|
||||
#![allow(deprecated)]
|
||||
let cmd = self
|
||||
.unset_global_setting(AppSettings::ColorAuto)
|
||||
.unset_global_setting(AppSettings::ColorAlways)
|
||||
|
@ -1724,31 +1733,9 @@ impl<'help> Command<'help> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Apply a setting for the current command or subcommand.
|
||||
///
|
||||
/// See [`Command::global_setting`] to apply a setting to this command and all subcommands.
|
||||
///
|
||||
/// See [`AppSettings`] for a full list of possibilities and examples.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .setting(AppSettings::SubcommandRequired)
|
||||
/// .setting(AppSettings::AllowHyphenValues)
|
||||
/// # ;
|
||||
/// ```
|
||||
/// or
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .setting(AppSettings::SubcommandRequired | AppSettings::AllowHyphenValues)
|
||||
/// # ;
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn setting<F>(mut self, setting: F) -> Self
|
||||
pub(crate) fn setting<F>(mut self, setting: F) -> Self
|
||||
where
|
||||
F: Into<AppFlags>,
|
||||
{
|
||||
|
@ -1756,29 +1743,9 @@ impl<'help> Command<'help> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Remove a setting for the current command or subcommand.
|
||||
///
|
||||
/// See [`AppSettings`] for a full list of possibilities and examples.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .unset_setting(AppSettings::SubcommandRequired)
|
||||
/// .setting(AppSettings::AllowHyphenValues)
|
||||
/// # ;
|
||||
/// ```
|
||||
/// or
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .unset_setting(AppSettings::SubcommandRequired | AppSettings::AllowHyphenValues)
|
||||
/// # ;
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn unset_setting<F>(mut self, setting: F) -> Self
|
||||
pub(crate) fn unset_setting<F>(mut self, setting: F) -> Self
|
||||
where
|
||||
F: Into<AppFlags>,
|
||||
{
|
||||
|
@ -1786,44 +1753,17 @@ impl<'help> Command<'help> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Apply a setting for the current command and all subcommands.
|
||||
///
|
||||
/// See [`Command::setting`] to apply a setting only to this command.
|
||||
///
|
||||
/// See [`AppSettings`] for a full list of possibilities and examples.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .global_setting(AppSettings::AllowNegativeNumbers)
|
||||
/// # ;
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn global_setting(mut self, setting: AppSettings) -> Self {
|
||||
pub(crate) fn global_setting(mut self, setting: AppSettings) -> Self {
|
||||
self.settings.set(setting);
|
||||
self.g_settings.set(setting);
|
||||
self
|
||||
}
|
||||
|
||||
/// Remove a setting and stop propagating down to subcommands.
|
||||
///
|
||||
/// See [`AppSettings`] for a full list of possibilities and examples.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use clap::{Command, AppSettings};
|
||||
/// Command::new("myprog")
|
||||
/// .unset_global_setting(AppSettings::AllowNegativeNumbers)
|
||||
/// # ;
|
||||
/// ```
|
||||
/// [global]: Command::global_setting()
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn unset_global_setting(mut self, setting: AppSettings) -> Self {
|
||||
pub(crate) fn unset_global_setting(mut self, setting: AppSettings) -> Self {
|
||||
self.settings.unset(setting);
|
||||
self.g_settings.unset(setting);
|
||||
self
|
||||
|
@ -3337,14 +3277,8 @@ impl<'help> Command<'help> {
|
|||
self.long_flag_aliases.iter().map(|a| a.0)
|
||||
}
|
||||
|
||||
/// Check if the given [`AppSettings`] variant is currently set on the `Command`.
|
||||
///
|
||||
/// This checks both [local] and [global settings].
|
||||
///
|
||||
/// [local]: Command::setting()
|
||||
/// [global settings]: Command::global_setting()
|
||||
#[inline]
|
||||
pub fn is_set(&self, s: AppSettings) -> bool {
|
||||
pub(crate) fn is_set(&self, s: AppSettings) -> bool {
|
||||
self.settings.is_set(s) || self.g_settings.is_set(s)
|
||||
}
|
||||
|
||||
|
@ -3354,7 +3288,6 @@ impl<'help> Command<'help> {
|
|||
debug!("Command::color: Color setting...");
|
||||
|
||||
if cfg!(feature = "color") {
|
||||
#[allow(deprecated)]
|
||||
if self.is_set(AppSettings::ColorNever) {
|
||||
debug!("Never");
|
||||
ColorChoice::Never
|
||||
|
@ -3853,7 +3786,6 @@ impl<'help> Command<'help> {
|
|||
self._propagate();
|
||||
self._check_help_and_version();
|
||||
self._propagate_global_args();
|
||||
self._derive_display_order();
|
||||
|
||||
let mut pos_counter = 1;
|
||||
let hide_pv = self.is_set(AppSettings::HidePossibleValues);
|
||||
|
@ -4366,27 +4298,6 @@ To change `help`s short, call `cmd.arg(Arg::new(\"help\")...)`.",
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn _derive_display_order(&mut self) {
|
||||
debug!("Command::_derive_display_order:{}", self.name);
|
||||
|
||||
if self.settings.is_set(AppSettings::DeriveDisplayOrder) {
|
||||
for a in self
|
||||
.args
|
||||
.args_mut()
|
||||
.filter(|a| !a.is_positional())
|
||||
.filter(|a| a.provider != ArgProvider::Generated)
|
||||
{
|
||||
a.disp_ord.make_explicit();
|
||||
}
|
||||
for (i, sc) in &mut self.subcommands.iter_mut().enumerate() {
|
||||
sc.disp_ord.get_or_insert(i);
|
||||
}
|
||||
}
|
||||
for sc in &mut self.subcommands {
|
||||
sc._derive_display_order();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn _render_version(&self, use_long: bool) -> String {
|
||||
debug!("Command::_render_version");
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ mod debug_asserts;
|
|||
mod tests;
|
||||
|
||||
pub use action::ArgAction;
|
||||
pub use app_settings::{AppFlags, AppSettings};
|
||||
pub use arg::Arg;
|
||||
pub use arg_group::ArgGroup;
|
||||
pub use command::Command;
|
||||
|
@ -43,6 +42,7 @@ pub use value_parser::OsStringValueParser;
|
|||
pub use value_parser::PathBufValueParser;
|
||||
|
||||
pub(crate) use action::CountType;
|
||||
pub(crate) use app_settings::AppSettings;
|
||||
pub(crate) use arg::display_arg_val;
|
||||
pub(crate) use arg_predicate::ArgPredicate;
|
||||
pub(crate) use arg_settings::{ArgFlags, ArgSettings};
|
||||
|
|
|
@ -109,7 +109,7 @@ pub(crate) use crate::util::color::ColorChoice;
|
|||
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use crate::builder::{AppFlags, AppSettings, PossibleValue, ValueHint};
|
||||
pub use crate::builder::{PossibleValue, ValueHint};
|
||||
pub use crate::error::{ErrorKind, Result};
|
||||
#[allow(deprecated)]
|
||||
pub use crate::parser::{Indices, ValueSource};
|
||||
|
|
|
@ -29,44 +29,6 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static REQUIRE_EQUALS: &str = "clap-test v1.4.8
|
||||
|
||||
USAGE:
|
||||
clap-test --opt=<FILE>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-o, --opt=<FILE> some
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static SKIP_POS_VALS: &str = "test 1.3
|
||||
Kevin K.
|
||||
tests stuff
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS] [arg1]
|
||||
|
||||
ARGS:
|
||||
<arg1> some pos arg
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-o, --opt <opt> some option
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static ARG_REQUIRED_ELSE_HELP: &str = "test 1.0
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-i, --info Provides more info
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
#[test]
|
||||
fn sub_command_negate_required() {
|
||||
Command::new("sub_command_negate")
|
||||
|
@ -163,6 +125,17 @@ fn arg_required_else_help_with_default() {
|
|||
|
||||
#[test]
|
||||
fn arg_required_else_help_error_message() {
|
||||
static ARG_REQUIRED_ELSE_HELP: &str = "test 1.0
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-i, --info Provides more info
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test")
|
||||
.arg_required_else_help(true)
|
||||
.version("1.0")
|
||||
|
@ -310,6 +283,22 @@ fn no_bin_name() {
|
|||
|
||||
#[test]
|
||||
fn skip_possible_values() {
|
||||
static SKIP_POS_VALS: &str = "test 1.3
|
||||
Kevin K.
|
||||
tests stuff
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS] [arg1]
|
||||
|
||||
ARGS:
|
||||
<arg1> some pos arg
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt <opt> some option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test")
|
||||
.author("Kevin K.")
|
||||
.about("tests stuff")
|
||||
|
@ -575,6 +564,17 @@ fn dont_collapse_args() {
|
|||
|
||||
#[test]
|
||||
fn require_eq() {
|
||||
static REQUIRE_EQUALS: &str = "clap-test v1.4.8
|
||||
|
||||
USAGE:
|
||||
clap-test --opt=<FILE>
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt=<FILE> some
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("clap-test").version("v1.4.8").arg(
|
||||
Arg::new("opt")
|
||||
.long("opt")
|
||||
|
|
|
@ -2,32 +2,6 @@ use super::utils;
|
|||
|
||||
use clap::{arg, Arg, ArgAction, Command};
|
||||
|
||||
static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-f, --flag [aliases: v_flg, flag2, flg3]
|
||||
-h, --help Print help information
|
||||
-o, --opt <opt> [aliases: visible]
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-f, --flag
|
||||
-h, --help Print help information
|
||||
-o, --opt <opt>
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
#[test]
|
||||
fn single_alias_of_option() {
|
||||
let a = Command::new("single_alias")
|
||||
|
@ -216,6 +190,19 @@ fn alias_on_a_subcommand_option() {
|
|||
|
||||
#[test]
|
||||
fn invisible_arg_aliases_help_output() {
|
||||
static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt <opt>
|
||||
-f, --flag
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("ct").author("Salim Afiune").subcommand(
|
||||
Command::new("test")
|
||||
.about("Some help")
|
||||
|
@ -234,6 +221,19 @@ fn invisible_arg_aliases_help_output() {
|
|||
|
||||
#[test]
|
||||
fn visible_arg_aliases_help_output() {
|
||||
static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt <opt> [aliases: visible]
|
||||
-f, --flag [aliases: v_flg, flag2, flg3]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("ct").author("Salim Afiune").subcommand(
|
||||
Command::new("test")
|
||||
.about("Some help")
|
||||
|
|
|
@ -2,32 +2,6 @@ use super::utils;
|
|||
|
||||
use clap::{arg, Arg, ArgAction, Command};
|
||||
|
||||
static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-f, --flag [aliases: flag1] [short aliases: a, b, 🦆]
|
||||
-h, --help Print help information
|
||||
-o, --opt <opt> [short aliases: v]
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-f, --flag
|
||||
-h, --help Print help information
|
||||
-o, --opt <opt>
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
#[test]
|
||||
fn single_short_alias_of_option() {
|
||||
let a = Command::new("single_alias")
|
||||
|
@ -183,6 +157,19 @@ fn short_alias_on_a_subcommand_option() {
|
|||
|
||||
#[test]
|
||||
fn invisible_short_arg_aliases_help_output() {
|
||||
static SC_INVISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt <opt>
|
||||
-f, --flag
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("ct").author("Salim Afiune").subcommand(
|
||||
Command::new("test")
|
||||
.about("Some help")
|
||||
|
@ -201,6 +188,19 @@ fn invisible_short_arg_aliases_help_output() {
|
|||
|
||||
#[test]
|
||||
fn visible_short_arg_aliases_help_output() {
|
||||
static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2
|
||||
Some help
|
||||
|
||||
USAGE:
|
||||
ct test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-o, --opt <opt> [short aliases: v]
|
||||
-f, --flag [aliases: flag1] [short aliases: a, b, 🦆]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("ct").author("Salim Afiune").subcommand(
|
||||
Command::new("test")
|
||||
.about("Some help")
|
||||
|
|
|
@ -2,111 +2,27 @@ use super::utils;
|
|||
|
||||
use std::str;
|
||||
|
||||
use clap::{AppSettings, Arg, Command};
|
||||
|
||||
static NO_DERIVE_ORDER: &str = "test 1.2
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_a second flag
|
||||
--flag_b first flag
|
||||
-h, --help Print help information
|
||||
--option_a <option_a> second option
|
||||
--option_b <option_b> first option
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static UNIFIED_HELP_AND_DERIVE: &str = "test 1.2
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--flag_a second flag
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static UNIFIED_DERIVE_SC_PROP: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--flag_a second flag
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_a second flag
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static PREFER_USER_HELP_DERIVE_ORDER: &str = "test 1.2
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help message
|
||||
--flag_b first flag
|
||||
--flag_a second flag
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static PREFER_USER_HELP_SUBCMD_DERIVE_ORDER: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help message
|
||||
--flag_b first flag
|
||||
--flag_a second flag
|
||||
-V, --version Print version information
|
||||
";
|
||||
use clap::{Arg, Command};
|
||||
|
||||
#[test]
|
||||
fn no_derive_order() {
|
||||
let cmd = Command::new("test").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]);
|
||||
static NO_DERIVE_ORDER: &str = "test 1.2
|
||||
|
||||
utils::assert_output(cmd, "test --help", NO_DERIVE_ORDER, false);
|
||||
}
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_a second flag
|
||||
--flag_b first flag
|
||||
-h, --help Print help information
|
||||
--option_a <option_a> second option
|
||||
--option_b <option_b> first option
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
#[test]
|
||||
fn derive_order() {
|
||||
let cmd = Command::new("test")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.version("1.2")
|
||||
.next_display_order(None)
|
||||
.args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
|
@ -120,6 +36,38 @@ fn derive_order() {
|
|||
.help("second option"),
|
||||
]);
|
||||
|
||||
utils::assert_output(cmd, "test --help", NO_DERIVE_ORDER, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_order() {
|
||||
static UNIFIED_HELP_AND_DERIVE: &str = "test 1.2
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--flag_a second flag
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]);
|
||||
|
||||
utils::assert_output(cmd, "test --help", UNIFIED_HELP_AND_DERIVE, false);
|
||||
}
|
||||
|
||||
|
@ -140,7 +88,6 @@ OPTIONS:
|
|||
";
|
||||
|
||||
let cmd = Command::new("test")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.version("1.2")
|
||||
.next_display_order(10000)
|
||||
.arg(Arg::new("flag_a").long("flag_a").help("second flag"))
|
||||
|
@ -179,7 +126,6 @@ OPTIONS:
|
|||
";
|
||||
|
||||
let cmd = Command::new("test")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.version("1.2")
|
||||
.next_display_order(None)
|
||||
.arg(Arg::new("flag_a").long("flag_a").help("first flag"))
|
||||
|
@ -202,47 +148,71 @@ OPTIONS:
|
|||
|
||||
#[test]
|
||||
fn derive_order_subcommand_propagate() {
|
||||
let cmd = Command::new("test")
|
||||
.global_setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]),
|
||||
);
|
||||
static UNIFIED_DERIVE_SC_PROP: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--flag_a second flag
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test").subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]),
|
||||
);
|
||||
|
||||
utils::assert_output(cmd, "test sub --help", UNIFIED_DERIVE_SC_PROP, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derive_order_subcommand_propagate_with_explicit_display_order() {
|
||||
let cmd = Command::new("test")
|
||||
.global_setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a")
|
||||
.long("flag_a")
|
||||
.help("second flag")
|
||||
.display_order(0),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]),
|
||||
);
|
||||
static UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--flag_a second flag
|
||||
--flag_b first flag
|
||||
--option_b <option_b> first option
|
||||
--option_a <option_a> second option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test").subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("option_b")
|
||||
.long("option_b")
|
||||
.takes_value(true)
|
||||
.help("first option"),
|
||||
Arg::new("flag_a")
|
||||
.long("flag_a")
|
||||
.help("second flag")
|
||||
.display_order(0),
|
||||
Arg::new("option_a")
|
||||
.long("option_a")
|
||||
.takes_value(true)
|
||||
.help("second option"),
|
||||
]),
|
||||
);
|
||||
|
||||
utils::assert_output(
|
||||
cmd,
|
||||
|
@ -254,35 +224,54 @@ fn derive_order_subcommand_propagate_with_explicit_display_order() {
|
|||
|
||||
#[test]
|
||||
fn prefer_user_help_with_derive_order() {
|
||||
let cmd = Command::new("test")
|
||||
.setting(AppSettings::DeriveDisplayOrder)
|
||||
.version("1.2")
|
||||
.args(&[
|
||||
Arg::new("help")
|
||||
.long("help")
|
||||
.short('h')
|
||||
.help("Print help message"),
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
]);
|
||||
static PREFER_USER_HELP_DERIVE_ORDER: &str = "test 1.2
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help message
|
||||
--flag_b first flag
|
||||
--flag_a second flag
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test").version("1.2").args(&[
|
||||
Arg::new("help")
|
||||
.long("help")
|
||||
.short('h')
|
||||
.help("Print help message"),
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
]);
|
||||
|
||||
utils::assert_output(cmd, "test --help", PREFER_USER_HELP_DERIVE_ORDER, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefer_user_help_in_subcommand_with_derive_order() {
|
||||
let cmd = Command::new("test")
|
||||
.global_setting(AppSettings::DeriveDisplayOrder)
|
||||
.subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("help")
|
||||
.long("help")
|
||||
.short('h')
|
||||
.help("Print help message"),
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
]),
|
||||
);
|
||||
static PREFER_USER_HELP_SUBCMD_DERIVE_ORDER: &str = "test-sub 1.2
|
||||
|
||||
USAGE:
|
||||
test sub [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help message
|
||||
--flag_b first flag
|
||||
--flag_a second flag
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test").subcommand(
|
||||
Command::new("sub").version("1.2").args(&[
|
||||
Arg::new("help")
|
||||
.long("help")
|
||||
.short('h')
|
||||
.help("Print help message"),
|
||||
Arg::new("flag_b").long("flag_b").help("first flag"),
|
||||
Arg::new("flag_a").long("flag_a").help("second flag"),
|
||||
]),
|
||||
);
|
||||
|
||||
utils::assert_output(
|
||||
cmd,
|
||||
|
@ -291,3 +280,74 @@ fn prefer_user_help_in_subcommand_with_derive_order() {
|
|||
false,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subcommand_sorted_display_order() {
|
||||
static SUBCMD_ALPHA_ORDER: &str = "test 1
|
||||
|
||||
USAGE:
|
||||
test [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
a1 blah a1
|
||||
b1 blah b1
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
let app_subcmd_alpha_order = Command::new("test")
|
||||
.version("1")
|
||||
.next_display_order(None)
|
||||
.subcommands(vec![
|
||||
Command::new("b1")
|
||||
.about("blah b1")
|
||||
.arg(Arg::new("test").short('t')),
|
||||
Command::new("a1")
|
||||
.about("blah a1")
|
||||
.arg(Arg::new("roster").short('r')),
|
||||
]);
|
||||
|
||||
utils::assert_output(
|
||||
app_subcmd_alpha_order,
|
||||
"test --help",
|
||||
SUBCMD_ALPHA_ORDER,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subcommand_derived_display_order() {
|
||||
static SUBCMD_DECL_ORDER: &str = "test 1
|
||||
|
||||
USAGE:
|
||||
test [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
b1 blah b1
|
||||
a1 blah a1
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
let app_subcmd_decl_order = Command::new("test").version("1").subcommands(vec![
|
||||
Command::new("b1")
|
||||
.about("blah b1")
|
||||
.arg(Arg::new("test").short('t')),
|
||||
Command::new("a1")
|
||||
.about("blah a1")
|
||||
.arg(Arg::new("roster").short('r')),
|
||||
]);
|
||||
|
||||
utils::assert_output(
|
||||
app_subcmd_decl_order,
|
||||
"test --help",
|
||||
SUBCMD_DECL_ORDER,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -499,9 +499,9 @@ USAGE:
|
|||
pacman {query|--query|-Q} [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-i, --info <info>... view package information
|
||||
-s, --search <search>... search locally installed packages for matching strings
|
||||
-i, --info <info>... view package information
|
||||
-h, --help Print help information
|
||||
";
|
||||
|
||||
#[test]
|
||||
|
@ -548,9 +548,9 @@ USAGE:
|
|||
pacman {query|--query} [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-i, --info <info>... view package information
|
||||
-s, --search <search>... search locally installed packages for matching strings
|
||||
-i, --info <info>... view package information
|
||||
-h, --help Print help information
|
||||
";
|
||||
|
||||
#[test]
|
||||
|
@ -601,9 +601,9 @@ USAGE:
|
|||
pacman {query|-Q} [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-i, --info <info>... view package information
|
||||
-s, --search <search>... search locally installed packages for matching strings
|
||||
-i, --info <info>... view package information
|
||||
-h, --help Print help information
|
||||
";
|
||||
|
||||
#[test]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,8 +11,8 @@ USAGE:
|
|||
|
||||
OPTIONS:
|
||||
-F, --flag2 some other flag
|
||||
-h, --help Print help information
|
||||
--option <opt> some option
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
|
@ -39,32 +39,11 @@ USAGE:
|
|||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-v, --visible This text should be visible
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "test 2.31.2
|
||||
Steve P.
|
||||
hides short args
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-c, --config
|
||||
Some help text describing the --config arg
|
||||
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-v, --visible
|
||||
This text should be visible
|
||||
|
||||
-V, --version
|
||||
Print version information
|
||||
";
|
||||
|
||||
/// Ensure hide with short option
|
||||
#[test]
|
||||
fn hide_short_args() {
|
||||
|
@ -90,6 +69,27 @@ fn hide_short_args() {
|
|||
/// Ensure visible with opposite option
|
||||
#[test]
|
||||
fn hide_short_args_long_help() {
|
||||
static HIDDEN_SHORT_ARGS_LONG_HELP: &str = "test 2.31.2
|
||||
Steve P.
|
||||
hides short args
|
||||
|
||||
USAGE:
|
||||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-c, --config
|
||||
Some help text describing the --config arg
|
||||
|
||||
-v, --visible
|
||||
This text should be visible
|
||||
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-V, --version
|
||||
Print version information
|
||||
";
|
||||
|
||||
let cmd = Command::new("test")
|
||||
.about("hides short args")
|
||||
.author("Steve P.")
|
||||
|
@ -117,12 +117,12 @@ USAGE:
|
|||
test [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-v, --visible
|
||||
This text should be visible
|
||||
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-V, --version
|
||||
Print version information
|
||||
";
|
||||
|
@ -157,8 +157,8 @@ USAGE:
|
|||
|
||||
OPTIONS:
|
||||
-c, --config Some help text describing the --config arg
|
||||
-h, --help Print help information
|
||||
-v, --visible This text should be visible
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
";
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test Some help [aliases: dongle, done]
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
static INVISIBLE_ALIAS_HELP: &str = "clap-test 2.6
|
||||
|
@ -26,37 +26,7 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test Some help
|
||||
";
|
||||
|
||||
static SUBCMD_ALPHA_ORDER: &str = "test 1
|
||||
|
||||
USAGE:
|
||||
test [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
a1 blah a1
|
||||
b1 blah b1
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
static SUBCMD_DECL_ORDER: &str = "test 1
|
||||
|
||||
USAGE:
|
||||
test [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
b1 blah b1
|
||||
a1 blah a1
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
|
@ -169,44 +139,6 @@ fn subcommand_multiple() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subcommand_display_order() {
|
||||
let app_subcmd_alpha_order = Command::new("test").version("1").subcommands(vec![
|
||||
Command::new("b1")
|
||||
.about("blah b1")
|
||||
.arg(Arg::new("test").short('t')),
|
||||
Command::new("a1")
|
||||
.about("blah a1")
|
||||
.arg(Arg::new("roster").short('r')),
|
||||
]);
|
||||
|
||||
utils::assert_output(
|
||||
app_subcmd_alpha_order,
|
||||
"test --help",
|
||||
SUBCMD_ALPHA_ORDER,
|
||||
false,
|
||||
);
|
||||
|
||||
let app_subcmd_decl_order = Command::new("test")
|
||||
.version("1")
|
||||
.setting(clap::AppSettings::DeriveDisplayOrder)
|
||||
.subcommands(vec![
|
||||
Command::new("b1")
|
||||
.about("blah b1")
|
||||
.arg(Arg::new("test").short('t')),
|
||||
Command::new("a1")
|
||||
.about("blah a1")
|
||||
.arg(Arg::new("roster").short('r')),
|
||||
]);
|
||||
|
||||
utils::assert_output(
|
||||
app_subcmd_decl_order,
|
||||
"test --help",
|
||||
SUBCMD_DECL_ORDER,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_alias() {
|
||||
let m = Command::new("myprog")
|
||||
|
|
|
@ -40,8 +40,8 @@ OPTIONS:
|
|||
ARGS:
|
||||
<output> Sets an optional output file
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test does testing things
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
static SIMPLE_TEMPLATE: &str = "MyApp 1.0
|
||||
|
@ -61,8 +61,8 @@ OPTIONS:
|
|||
-V, --version Print version information
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
test does testing things
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
";
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{AppSettings, Args, CommandFactory, Parser, Subcommand};
|
||||
use clap::{Args, CommandFactory, Parser, Subcommand};
|
||||
|
||||
#[test]
|
||||
fn arg_help_heading_applied() {
|
||||
|
@ -247,7 +247,6 @@ OPTIONS:
|
|||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(name = "test", version = "1.2")]
|
||||
#[clap(setting = AppSettings::DeriveDisplayOrder)]
|
||||
struct Args {
|
||||
#[clap(flatten)]
|
||||
a: A,
|
||||
|
@ -303,7 +302,6 @@ OPTIONS:
|
|||
";
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(setting = AppSettings::DeriveDisplayOrder)]
|
||||
#[clap(name = "test", version = "1.2")]
|
||||
struct Args {
|
||||
#[clap(flatten)]
|
||||
|
@ -361,7 +359,6 @@ OPTIONS:
|
|||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(name = "test", version = "1.2")]
|
||||
#[clap(setting = AppSettings::DeriveDisplayOrder)]
|
||||
#[clap(next_display_order = None)]
|
||||
struct Args {
|
||||
#[clap(flatten)]
|
||||
|
|
|
@ -9,11 +9,11 @@ USAGE:
|
|||
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
--verbose log
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
--verbose log
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
more
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
"""
|
||||
|
|
|
@ -8,12 +8,12 @@ USAGE:
|
|||
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
--verbose log
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
--verbose log
|
||||
|
||||
SUBCOMMANDS:
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
more
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
"""
|
||||
stderr = ""
|
||||
|
|
|
@ -8,19 +8,19 @@ USAGE:
|
|||
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
--verbose
|
||||
more log
|
||||
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-V, --version
|
||||
Print version information
|
||||
|
||||
--verbose
|
||||
more log
|
||||
|
||||
SUBCOMMANDS:
|
||||
help
|
||||
Print this message or the help of the given subcommand(s)
|
||||
more
|
||||
|
||||
help
|
||||
Print this message or the help of the given subcommand(s)
|
||||
"""
|
||||
stderr = ""
|
||||
|
|
|
@ -8,19 +8,19 @@ USAGE:
|
|||
stdio-fixture[EXE] [OPTIONS] [SUBCOMMAND]
|
||||
|
||||
OPTIONS:
|
||||
--verbose
|
||||
more log
|
||||
|
||||
-h, --help
|
||||
Print help information
|
||||
|
||||
-V, --version
|
||||
Print version information
|
||||
|
||||
--verbose
|
||||
more log
|
||||
|
||||
SUBCOMMANDS:
|
||||
help
|
||||
Print this message or the help of the given subcommand(s)
|
||||
more
|
||||
|
||||
help
|
||||
Print this message or the help of the given subcommand(s)
|
||||
"""
|
||||
stderr = ""
|
||||
|
|
Loading…
Reference in a new issue