feat: Replace core set of AppSettings with functions

This is a part of #2717

Some settings didn't get getters because
- They are transient parse settings (e.g. ignore errors)
- They get propagated to args and should be checked there

`is_allow_hyphen_values_set` is a curious case.  In some cases, we only
check the app and not an arg.  This seems suspicious.
This commit is contained in:
Ed Page 2022-02-10 11:51:40 -06:00
parent de7c81e059
commit 272f840178
53 changed files with 1591 additions and 1066 deletions

View file

@ -1,4 +1,4 @@
use clap::{arg, App, AppSettings, Arg};
use clap::{arg, App, Arg};
use criterion::{criterion_group, criterion_main, Criterion};
static OPT3_VALS: [&str; 2] = ["fast", "slow"];
@ -257,7 +257,7 @@ pub fn parse_args_negate_scs(c: &mut Criterion) {
c.bench_function("parse_args_negate_scs", |b| {
b.iter(|| {
create_app!()
.setting(AppSettings::ArgsNegateSubcommands)
.args_conflicts_with_subcommands(true)
.get_matches_from(vec![
"myprog",
"arg1",

View file

@ -43,7 +43,7 @@ fn build_cli() -> App<'static> {
App::new("install")
.about("Update Rust toolchains")
.after_help(TOOLCHAIN_INSTALL_HELP)
.setting(AppSettings::Hidden) // synonym for 'toolchain install'
.hide(true) // synonym for 'toolchain install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
@ -89,17 +89,17 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("update")
.setting(AppSettings::Hidden) // synonym for 'install'
.hide(true) // synonym for 'install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("add")
.setting(AppSettings::Hidden) // synonym for 'install'
.hide(true) // synonym for 'install'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'uninstall'
.hide(true) // synonym for 'uninstall'
.arg(Arg::new("toolchain").required(true)),
),
)
@ -127,13 +127,13 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("install")
.setting(AppSettings::Hidden) // synonym for 'add'
.hide(true) // synonym for 'add'
.arg(Arg::new("target").required(true))
.arg(Arg::new("toolchain").long("toolchain").takes_value(true)),
)
.subcommand(
App::new("uninstall")
.setting(AppSettings::Hidden) // synonym for 'remove'
.hide(true) // synonym for 'remove'
.arg(Arg::new("target").required(true))
.arg(Arg::new("toolchain").long("toolchain").takes_value(true)),
),
@ -193,12 +193,12 @@ fn build_cli() -> App<'static> {
)
.subcommand(
App::new("add")
.setting(AppSettings::Hidden) // synonym for 'set'
.hide(true) // synonym for 'set'
.arg(Arg::new("toolchain").required(true)),
)
.subcommand(
App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'unset'
.hide(true) // synonym for 'unset'
.about("Remove the override toolchain for a directory")
.arg(Arg::new("path").long("path").takes_value(true))
.arg(
@ -212,7 +212,7 @@ fn build_cli() -> App<'static> {
App::new("run")
.about("Run a command with an environment configured for a given toolchain")
.after_help(RUN_HELP)
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(Arg::new("toolchain").required(true))
.arg(
Arg::new("command")
@ -264,7 +264,7 @@ fn build_cli() -> App<'static> {
.subcommand(
App::new("telemetry")
.about("rustup telemetry commands")
.setting(AppSettings::Hidden)
.hide(true)
.setting(AppSettings::DeriveDisplayOrder)
.subcommand(App::new("enable").about("Enable rustup telemetry"))
.subcommand(App::new("disable").about("Disable rustup telemetry"))

View file

@ -12,14 +12,14 @@
//! . ./value_hints.fish
//! ./target/debug/examples/value_hints --<TAB>
//! ```
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, Generator, Shell};
use std::io;
fn build_cli() -> App<'static> {
App::new("value_hints")
// AppSettings::TrailingVarArg is required to use ValueHint::CommandWithArguments
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(
Arg::new("generator")
.long("generate")

View file

@ -12,7 +12,7 @@
//! . ./value_hints_derive.fish
//! ./target/debug/examples/value_hints_derive --<TAB>
//! ```
use clap::{App, AppSettings, IntoApp, Parser, ValueHint};
use clap::{App, IntoApp, Parser, ValueHint};
use clap_complete::{generate, Generator, Shell};
use std::ffi::OsString;
use std::io;
@ -21,8 +21,8 @@ use std::path::PathBuf;
#[derive(Parser, Debug, PartialEq)]
#[clap(
name = "value_hints_derive",
// AppSettings::TrailingVarArg is required to use ValueHint::CommandWithArguments
setting = AppSettings::TrailingVarArg,
// App::trailing_var_ar is required to use ValueHint::CommandWithArguments
trailing_var_arg = true,
)]
struct Opt {
/// If provided, outputs the completion file for given shell

View file

@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")

View file

@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")

View file

@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")

View file

@ -1,4 +1,4 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, shells::*, Generator};
use std::fmt;

View file

@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")

View file

@ -7,7 +7,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Test test's completions")
.arg(
Arg::new("file")

View file

@ -1,13 +1,13 @@
mod completions;
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::shells::*;
use completions::common;
pub fn build_app_with_value_hints() -> App<'static> {
App::new("my_app")
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(
Arg::new("choice")
.long("choice")

View file

@ -8,7 +8,7 @@ fn build_app() -> App<'static> {
fn build_app_with_name(s: &'static str) -> App<'static> {
App::new(s)
.version("3.0")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.about("Tests completions")
.arg(
Arg::new("file")

View file

@ -1,4 +1,4 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete::{generate, Generator};
use std::fmt;

View file

@ -1,4 +1,4 @@
use clap::{App, AppSettings, Arg, ValueHint};
use clap::{App, Arg, ValueHint};
use clap_complete_fig::Fig;
use completions::common;
@ -6,8 +6,8 @@ mod completions;
pub fn build_app_with_value_hints() -> App<'static> {
App::new("my_app")
.setting(AppSettings::DisableVersionFlag)
.setting(AppSettings::TrailingVarArg)
.disable_version_flag(true)
.trailing_var_arg(true)
.arg(
Arg::new("choice")
.long("choice")

View file

@ -165,11 +165,11 @@ fn gen_augment(
Some(subty) => {
if is_simple_ty(subty, "OsString") {
quote_spanned! { kind.span()=>
let #app_var = #app_var.setting(clap::AppSettings::AllowExternalSubcommands).setting(clap::AppSettings::AllowInvalidUtf8ForExternalSubcommands);
let #app_var = #app_var.allow_external_subcommands(true).allow_invalid_utf8_for_external_subcommands(true);
}
} else {
quote_spanned! { kind.span()=>
let #app_var = #app_var.setting(clap::AppSettings::AllowExternalSubcommands);
let #app_var = #app_var.allow_external_subcommands(true);
}
}
}

View file

@ -264,6 +264,5 @@ fn app_has_arguments(app: &clap::App) -> bool {
// Does the application have any subcommands?
fn app_has_subcommands(app: &clap::App) -> bool {
app.get_subcommands()
.any(|i| !i.is_set(clap::AppSettings::Hidden))
app.get_subcommands().any(|i| !i.is_hide_set())
}

View file

@ -144,10 +144,7 @@ pub(crate) fn options(roff: &mut Roff, app: &clap::App) {
}
pub(crate) fn subcommands(roff: &mut Roff, app: &clap::App, section: &str) {
for sub in app
.get_subcommands()
.filter(|s| !s.is_set(AppSettings::Hidden))
{
for sub in app.get_subcommands().filter(|s| !s.is_hide_set()) {
roff.control("TP", []);
let name = format!("{}-{}({})", app.get_name(), sub.get_name(), section);
@ -179,10 +176,7 @@ pub(crate) fn after_help(roff: &mut Roff, app: &clap::App) {
}
fn subcommand_markers(cmd: &clap::App) -> (&'static str, &'static str) {
markers(
cmd.is_set(AppSettings::SubcommandRequired)
|| cmd.is_set(AppSettings::SubcommandRequiredElseHelp),
)
markers(cmd.is_subcommand_required_set() || cmd.is_set(AppSettings::SubcommandRequiredElseHelp))
}
fn option_markers(opt: &clap::Arg) -> (&'static str, &'static str) {

View file

@ -3,7 +3,7 @@
fn main() {
let app = clap::App::new("cargo")
.bin_name("cargo")
.setting(clap::AppSettings::SubcommandRequired)
.subcommand_required(true)
.subcommand(
clap::app_from_crate!().name("example").arg(
clap::arg!(--"manifest-path" <PATH>)

View file

@ -3,7 +3,7 @@
use std::ffi::OsString;
use std::path::PathBuf;
use clap::{AppSettings, Parser, Subcommand};
use clap::{Parser, Subcommand};
/// A fictional versioning CLI
#[derive(Parser)]
@ -17,19 +17,19 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Clones repos
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Clone {
/// The remote to clone
remote: String,
},
/// pushes things
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Push {
/// The remote to target
remote: String,
},
/// adds things
#[clap(setting(AppSettings::ArgRequiredElseHelp))]
#[clap(arg_required_else_help = true)]
Add {
/// Stuff to add
#[clap(required = true, parse(from_os_str))]

View file

@ -8,24 +8,24 @@ fn main() {
let matches = App::new("git")
.about("A fictional versioning CLI")
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.subcommand(
App::new("clone")
.about("Clones repos")
.arg(arg!(<REMOTE> "The remote to clone"))
.setting(AppSettings::ArgRequiredElseHelp),
.arg_required_else_help(true),
)
.subcommand(
App::new("push")
.about("pushes things")
.arg(arg!(<REMOTE> "The remote to target"))
.setting(AppSettings::ArgRequiredElseHelp),
.arg_required_else_help(true),
)
.subcommand(
App::new("add")
.about("adds things")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(arg!(<PATH> ... "Stuff to add").allow_invalid_utf8(true)),
)
.get_matches();

View file

@ -2,7 +2,7 @@
use std::process::exit;
use clap::{App, AppSettings, Arg};
use clap::{App, Arg};
fn applet_commands() -> [App<'static>; 2] {
[
@ -13,10 +13,10 @@ fn applet_commands() -> [App<'static>; 2] {
fn main() {
let app = App::new(env!("CARGO_CRATE_NAME"))
.setting(AppSettings::Multicall)
.multicall(true)
.subcommand(
App::new("busybox")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.subcommand_value_name("APPLET")
.subcommand_help_heading("APPLETS")
.arg(

View file

@ -1,16 +1,16 @@
// Note: this requires the `unstable-multicall` feature
use clap::{App, AppSettings};
use clap::App;
fn main() {
let app = App::new(env!("CARGO_CRATE_NAME"))
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.subcommand_value_name("APPLET")
.subcommand_help_heading("APPLETS")
.subcommand(App::new("hostname").about("show hostname part of FQDN"))
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN"));
let app = app.setting(AppSettings::Multicall);
let app = app.multicall(true);
match app.get_matches().subcommand_name() {
Some("hostname") => println!("www"),

View file

@ -2,9 +2,9 @@ use clap::{app_from_crate, arg, AppSettings};
fn main() {
let matches = app_from_crate!()
.global_setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.global_setting(AppSettings::DeriveDisplayOrder)
.global_setting(AppSettings::AllowNegativeNumbers)
.allow_negative_numbers(true)
.arg(arg!(--two <VALUE>))
.arg(arg!(--one <VALUE>))
.get_matches();

View file

@ -2,7 +2,7 @@ use clap::{app_from_crate, arg, App, AppSettings};
fn main() {
let matches = app_from_crate!()
.global_setting(AppSettings::PropagateVersion)
.propagate_version(true)
.global_setting(AppSettings::UseLongFormatForHelpSubcommand)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(

View file

@ -326,7 +326,7 @@ SUBCOMMANDS:
```
Because we set `AppSettings::PropagateVersion`:
Because we set `App::propagate_version`:
```console
$ 03_04_subcommands --version
clap [..]

View file

@ -2,9 +2,9 @@ use clap::{AppSettings, Parser};
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(global_setting(AppSettings::AllArgsOverrideSelf))]
#[clap(args_override_self = true)]
#[clap(allow_negative_numbers = true)]
#[clap(global_setting(AppSettings::DeriveDisplayOrder))]
#[clap(global_setting(AppSettings::AllowNegativeNumbers))]
struct Cli {
#[clap(long)]
two: String,

View file

@ -2,7 +2,7 @@ use clap::{AppSettings, Parser, Subcommand};
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(global_setting(AppSettings::PropagateVersion))]
#[clap(propagate_version = true)]
#[clap(global_setting(AppSettings::UseLongFormatForHelpSubcommand))]
struct Cli {
#[clap(subcommand)]

View file

@ -328,7 +328,7 @@ SUBCOMMANDS:
```
Because we set `AppSettings::PropagateVersion`:
Because we set `App::propagate_version`:
```console
$ 03_04_subcommands_derive --version
clap [..]

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,15 @@
#![allow(deprecated)]
// Std
use std::ops::BitOr;
#[cfg(feature = "yaml")]
use std::str::FromStr;
#[allow(unused)]
use crate::App;
#[allow(unused)]
use crate::Arg;
// Third party
use bitflags::bitflags;
@ -25,27 +32,8 @@ impl Default for AppFlags {
#[derive(Debug, PartialEq, Copy, Clone)]
#[non_exhaustive]
pub enum AppSettings {
/// Try not to fail on parse errors, like missing option values.
///
/// **Note:** Make sure you apply it as `global_setting` if you want this setting
/// to be propagated to subcommands and sub-subcommands!
///
/// ```rust
/// # use clap::{App, arg, AppSettings};
/// let app = App::new("app")
/// .global_setting(AppSettings::IgnoreErrors)
/// .arg(arg!(-c --config <FILE> "Sets a custom config file").required(false))
/// .arg(arg!(-x --stuff <FILE> "Sets a custom stuff file").required(false))
/// .arg(arg!(f: -f "Flag"));
///
/// let r = app.try_get_matches_from(vec!["app", "-c", "file", "-f", "-x"]);
///
/// assert!(r.is_ok(), "unexpected error: {:?}", r);
/// let m = r.unwrap();
/// assert_eq!(m.value_of("config"), Some("file"));
/// assert!(m.is_present("f"));
/// assert_eq!(m.value_of("stuff"), None);
/// ```
/// Deprecated, replaced with [`App::ignore_errors`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::ignore_errors`")]
IgnoreErrors,
/// Deprecated, replace
@ -85,275 +73,63 @@ pub enum AppSettings {
)]
WaitOnError,
/// Specifies that leading hyphens are allowed in all argument *values* (e.g. `-10`).
///
/// Otherwise they will be parsed as another flag or option. See also
/// [`AppSettings::AllowNegativeNumbers`].
///
/// **NOTE:** Use this setting with caution as it silences certain circumstances which would
/// otherwise be an error (such as accidentally forgetting to specify a value for leading
/// option). It is preferred to set this on a per argument basis, via [`Arg::allow_hyphen_values`].
///
/// # Examples
///
/// ```rust
/// # use clap::{Arg, App, AppSettings};
/// // Imagine you needed to represent negative numbers as well, such as -10
/// let m = App::new("nums")
/// .setting(AppSettings::AllowHyphenValues)
/// .arg(Arg::new("neg"))
/// .get_matches_from(vec![
/// "nums", "-20"
/// ]);
///
/// assert_eq!(m.value_of("neg"), Some("-20"));
/// # ;
/// ```
/// [`Arg::allow_hyphen_values`]: crate::Arg::allow_hyphen_values()
/// Deprecated, replaced with [`App::allow_hyphen_values`] and
/// [`Arg::is_allow_hyphen_values_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::allow_hyphen_values` and `Arg::is_allow_hyphen_values_set`"
)]
AllowHyphenValues,
/// Allows negative numbers to pass as values.
///
/// This is similar to [`AppSettings::AllowHyphenValues`] except that it only allows numbers,
/// all other undefined leading hyphens will fail to parse.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// let res = App::new("myprog")
/// .global_setting(AppSettings::AllowNegativeNumbers)
/// .arg(Arg::new("num"))
/// .try_get_matches_from(vec![
/// "myprog", "-20"
/// ]);
/// assert!(res.is_ok());
/// let m = res.unwrap();
/// assert_eq!(m.value_of("num").unwrap(), "-20");
/// ```
/// Deprecated, replaced with [`App::allow_negative_numbers`] and
/// [`App::is_allow_negative_numbers_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::allow_negative_numbers` and `App::is_allow_negative_numbers_set`"
)]
AllowNegativeNumbers,
/// Specifies that all arguments override themselves.
///
/// This is the equivalent to saying the `foo` arg using [`Arg::overrides_with("foo")`] for all
/// defined arguments.
///
/// [`Arg::overrides_with("foo")`]: crate::Arg::overrides_with()
/// Deprecated, replaced with [`App::args_override_self`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::args_override_self`")]
AllArgsOverrideSelf,
/// Allows one to implement two styles of CLIs where positionals can be used out of order.
///
/// The first example is a CLI where the second to last positional argument is optional, but
/// the final positional argument is required. Such as `$ prog [optional] <required>` where one
/// of the two following usages is allowed:
///
/// * `$ prog [optional] <required>`
/// * `$ prog <required>`
///
/// This would otherwise not be allowed. This is useful when `[optional]` has a default value.
///
/// **Note:** when using this style of "missing positionals" the final positional *must* be
/// [required] if `--` will not be used to skip to the final positional argument.
///
/// **Note:** This style also only allows a single positional argument to be "skipped" without
/// the use of `--`. To skip more than one, see the second example.
///
/// The second example is when one wants to skip multiple optional positional arguments, and use
/// of the `--` operator is OK (but not required if all arguments will be specified anyways).
///
/// For example, imagine a CLI which has three positional arguments `[foo] [bar] [baz]...` where
/// `baz` accepts multiple values (similar to man `ARGS...` style training arguments).
///
/// With this setting the following invocations are posisble:
///
/// * `$ prog foo bar baz1 baz2 baz3`
/// * `$ prog foo -- baz1 baz2 baz3`
/// * `$ prog -- baz1 baz2 baz3`
///
/// # Examples
///
/// Style number one from above:
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowMissingPositional)
/// .arg(Arg::new("arg1"))
/// .arg(Arg::new("arg2")
/// .required(true))
/// .get_matches_from(vec![
/// "prog", "other"
/// ]);
///
/// assert_eq!(m.value_of("arg1"), None);
/// assert_eq!(m.value_of("arg2"), Some("other"));
/// ```
///
/// Now the same example, but using a default value for the first optional positional argument
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowMissingPositional)
/// .arg(Arg::new("arg1")
/// .default_value("something"))
/// .arg(Arg::new("arg2")
/// .required(true))
/// .get_matches_from(vec![
/// "prog", "other"
/// ]);
///
/// assert_eq!(m.value_of("arg1"), Some("something"));
/// assert_eq!(m.value_of("arg2"), Some("other"));
/// ```
///
/// Style number two from above:
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowMissingPositional)
/// .arg(Arg::new("foo"))
/// .arg(Arg::new("bar"))
/// .arg(Arg::new("baz").takes_value(true).multiple_values(true))
/// .get_matches_from(vec![
/// "prog", "foo", "bar", "baz1", "baz2", "baz3"
/// ]);
///
/// assert_eq!(m.value_of("foo"), Some("foo"));
/// assert_eq!(m.value_of("bar"), Some("bar"));
/// assert_eq!(m.values_of("baz").unwrap().collect::<Vec<_>>(), &["baz1", "baz2", "baz3"]);
/// ```
///
/// Now nofice if we don't specify `foo` or `baz` but use the `--` operator.
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowMissingPositional)
/// .arg(Arg::new("foo"))
/// .arg(Arg::new("bar"))
/// .arg(Arg::new("baz").takes_value(true).multiple_values(true))
/// .get_matches_from(vec![
/// "prog", "--", "baz1", "baz2", "baz3"
/// ]);
///
/// assert_eq!(m.value_of("foo"), None);
/// assert_eq!(m.value_of("bar"), None);
/// assert_eq!(m.values_of("baz").unwrap().collect::<Vec<_>>(), &["baz1", "baz2", "baz3"]);
/// ```
///
/// [required]: crate::Arg::required()
/// Deprecated, replaced with [`App::allow_missing_positional`] and
/// [`App::is_allow_missing_positional_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::allow_missing_positional` and `App::is_allow_missing_positional_set`"
)]
AllowMissingPositional,
/// Specifies that the final positional argument is a "VarArg" and that `clap` should not
/// attempt to parse any further args.
///
/// The values of the trailing positional argument will contain all args from itself on.
///
/// **NOTE:** The final positional argument **must** have [`Arg::multiple_values(true)`] or the usage
/// string equivalent.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, arg, AppSettings};
/// let m = App::new("myprog")
/// .setting(AppSettings::TrailingVarArg)
/// .arg(arg!(<cmd> ... "commands to run"))
/// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]);
///
/// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect();
/// assert_eq!(trail, ["arg1", "-r", "val1"]);
/// ```
/// [`Arg::multiple_values(true)`]: crate::Arg::multiple_values()
/// Deprecated, replaced with [`App::trailing_var_arg`] and [`App::is_trailing_var_arg_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::trailing_var_arg` and `App::is_trailing_var_arg_set`"
)]
TrailingVarArg,
/// Disables the automatic delimiting of values when `--` or [`AppSettings::TrailingVarArg`]
/// was used.
///
/// **NOTE:** The same thing can be done manually by setting the final positional argument to
/// [`Arg::use_value_delimiter(false)`]. Using this setting is safer, because it's easier to locate
/// when making changes.
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::DontDelimitTrailingValues)
/// .get_matches();
/// ```
///
/// [`Arg::use_value_delimiter(false)`]: crate::Arg::use_value_delimiter()
/// Deprecated, replaced with [`App::dont_delimit_trailing_values`] and
/// [`App::is_dont_delimit_trailing_values_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::dont_delimit_trailing_values` and `App::is_dont_delimit_trailing_values_set`"
)]
DontDelimitTrailingValues,
/// Allow partial matches of long arguments or their [aliases].
///
/// For example, to match an argument named `--test`, one could use `--t`, `--te`, `--tes`, and
/// `--test`.
///
/// **NOTE:** The match *must not* be ambiguous at all in order to succeed. i.e. to match
/// `--te` to `--test` there could not also be another argument or alias `--temp` because both
/// start with `--te`
///
/// [aliases]: crate::App::aliases()
/// Deprecated, replaced with [`App::infer_long_args`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::infer_long_args`")]
InferLongArgs,
/// Allow partial matches of [subcommand] names and their [aliases].
///
/// For example, to match a subcommand named `test`, one could use `t`, `te`, `tes`, and
/// `test`.
///
/// **NOTE:** The match *must not* be ambiguous at all in order to succeed. i.e. to match `te`
/// to `test` there could not also be a subcommand or alias `temp` because both start with `te`
///
/// **CAUTION:** This setting can interfere with [positional/free arguments], take care when
/// designing CLIs which allow inferred subcommands and have potential positional/free
/// arguments whose values could start with the same characters as subcommands. If this is the
/// case, it's recommended to use settings such as [`AppSettings::ArgsNegateSubcommands`] in
/// conjunction with this setting.
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// let m = App::new("prog")
/// .global_setting(AppSettings::InferSubcommands)
/// .subcommand(App::new("test"))
/// .get_matches_from(vec![
/// "prog", "te"
/// ]);
/// assert_eq!(m.subcommand_name(), Some("test"));
/// ```
///
/// [subcommand]: crate::App::subcommand()
/// [positional/free arguments]: crate::Arg::index()
/// [aliases]: crate::App::aliases()
/// Deprecated, replaced with [`App::infer_subcommands`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::infer_subcommands`")]
InferSubcommands,
/// If no [`subcommand`] is present at runtime, error and exit gracefully.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings, ErrorKind};
/// let err = App::new("myprog")
/// .setting(AppSettings::SubcommandRequired)
/// .subcommand(App::new("test"))
/// .try_get_matches_from(vec![
/// "myprog",
/// ]);
/// assert!(err.is_err());
/// assert_eq!(err.unwrap_err().kind(), ErrorKind::MissingSubcommand);
/// # ;
/// ```
///
/// [`subcommand`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::subcommand_required`] and
/// [`App::is_subcommand_required_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::subcommand_required` and `App::is_subcommand_required_set`"
)]
SubcommandRequired,
/// Display help if no [`subcommands`] are present at runtime and exit gracefully (i.e. an
@ -377,177 +153,27 @@ pub enum AppSettings {
/// [`subcommands`]: crate::App::subcommand()
SubcommandRequiredElseHelp,
/// Assume unexpected positional arguments are a [`subcommand`].
///
/// **NOTE:** Use this setting with caution,
/// as a truly unexpected argument (i.e. one that is *NOT* an external subcommand)
/// will **not** cause an error and instead be treated as a potential subcommand.
/// One should check for such cases manually and inform the user appropriately.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowExternalSubcommands)
/// .get_matches_from(vec![
/// "myprog", "subcmd", "--option", "value", "-fff", "--flag"
/// ]);
///
/// // All trailing arguments will be stored under the subcommand's sub-matches using an empty
/// // string argument name
/// match m.subcommand() {
/// Some((external, ext_m)) => {
/// let ext_args: Vec<&str> = ext_m.values_of("").unwrap().collect();
/// assert_eq!(external, "subcmd");
/// assert_eq!(ext_args, ["--option", "value", "-fff", "--flag"]);
/// },
/// _ => {},
/// }
/// ```
///
/// [`subcommand`]: crate::App::subcommand()
/// [`ArgMatches`]: crate::ArgMatches
/// [`ErrorKind::UnknownArgument`]: crate::ErrorKind::UnknownArgument
/// Deprecated, replaced with [`App::allow_external_subcommands`] and
/// [`App::is_allow_external_subcommands_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::allow_external_subcommands` and `App::is_allow_external_subcommands_set`"
)]
AllowExternalSubcommands,
/// Strip directory path from argv\[0\] and use as an argument.
///
/// A "multicall" executable is a single executable
/// that contains a variety of applets,
/// and decides which applet to run based on the name of the file.
/// The executable can be called from different names by creating hard links
/// or symbolic links to it.
///
/// This is desirable when it is convenient to store code
/// for many programs in the same file,
/// such as deduplicating code across multiple programs
/// without loading a shared library at runtime.
///
/// Multicall can't be used with [`NoBinaryName`] since they interpret
/// the command name in incompatible ways.
///
/// # Examples
///
/// `hostname` is an example of a multicall executable.
/// Both `hostname` and `dnsdomainname` are provided by the same executable
/// and which behaviour to use is based on the executable file name.
///
/// This is desirable when the executable has a primary purpose
/// but there is other related functionality that would be convenient to provide
/// and it is convenient for the code to implement it to be in the same executable.
///
/// The name of the app is essentially unused
/// and may be the same as the name of a subcommand.
///
/// The names of the immediate subcommands of the App
/// are matched against the basename of the first argument,
/// which is conventionally the path of the executable.
///
/// This does not allow the subcommand to be passed as the first non-path argument.
///
/// ```rust
/// # use clap::{App, AppSettings, ErrorKind};
/// let mut app = App::new("hostname")
/// .setting(AppSettings::Multicall)
/// .subcommand(App::new("hostname"))
/// .subcommand(App::new("dnsdomainname"));
/// let m = app.try_get_matches_from_mut(&["/usr/bin/hostname", "dnsdomainname"]);
/// assert!(m.is_err());
/// assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// let m = app.get_matches_from(&["/usr/bin/dnsdomainname"]);
/// assert_eq!(m.subcommand_name(), Some("dnsdomainname"));
/// ```
///
/// Busybox is another common example of a multicall executable
/// with a subcommmand for each applet that can be run directly,
/// e.g. with the `cat` applet being run by running `busybox cat`,
/// or with `cat` as a link to the `busybox` binary.
///
/// This is desirable when the launcher program has additional options
/// or it is useful to run the applet without installing a symlink
/// e.g. to test the applet without installing it
/// or there may already be a command of that name installed.
///
/// To make an applet usable as both a multicall link and a subcommand
/// the subcommands must be defined both in the top-level App
/// and as subcommands of the "main" applet.
///
/// ```rust
/// # use clap::{App, AppSettings};
/// fn applet_commands() -> [App<'static>; 2] {
/// [App::new("true"), App::new("false")]
/// }
/// let mut app = App::new("busybox")
/// .setting(AppSettings::Multicall)
/// .subcommand(
/// App::new("busybox")
/// .subcommand_value_name("APPLET")
/// .subcommand_help_heading("APPLETS")
/// .subcommands(applet_commands()),
/// )
/// .subcommands(applet_commands());
/// // When called from the executable's canonical name
/// // its applets can be matched as subcommands.
/// let m = app.try_get_matches_from_mut(&["/usr/bin/busybox", "true"]).unwrap();
/// assert_eq!(m.subcommand_name(), Some("busybox"));
/// assert_eq!(m.subcommand().unwrap().1.subcommand_name(), Some("true"));
/// // When called from a link named after an applet that applet is matched.
/// let m = app.get_matches_from(&["/usr/bin/true"]);
/// assert_eq!(m.subcommand_name(), Some("true"));
/// ```
///
/// **NOTE:** Applets are slightly semantically different from subcommands,
/// so it's recommended to use [`App::subcommand_help_heading`] and
/// [`App::subcommand_value_name`] to change the descriptive text as above.
///
/// [`NoBinaryName`]: crate::AppSettings::NoBinaryName
/// [`App::subcommand_value_name`]: crate::App::subcommand_value_name
/// [`App::subcommand_help_heading`]: crate::App::subcommand_help_heading
/// Deprecated, replaced with [`App::multicall`] and [`App::is_multicall_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::multicall` and `App::is_multicall_set`"
)]
#[cfg(feature = "unstable-multicall")]
Multicall,
/// Specifies that external subcommands that are invalid UTF-8 should *not* be treated as an error.
///
/// **NOTE:** Using external subcommand argument values with invalid UTF-8 requires using
/// [`ArgMatches::values_of_os`] or [`ArgMatches::values_of_lossy`] for those particular
/// arguments which may contain invalid UTF-8 values
///
/// **NOTE:** Setting this requires [`AppSettings::AllowExternalSubcommands`]
///
/// # Platform Specific
///
/// Non Windows systems only
///
/// # Examples
///
#[cfg_attr(not(unix), doc = " ```ignore")]
#[cfg_attr(unix, doc = " ```")]
/// # use clap::{App, AppSettings};
/// // Assume there is an external subcommand named "subcmd"
/// let m = App::new("myprog")
/// .setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
/// .setting(AppSettings::AllowExternalSubcommands)
/// .get_matches_from(vec![
/// "myprog", "subcmd", "--option", "value", "-fff", "--flag"
/// ]);
///
/// // All trailing arguments will be stored under the subcommand's sub-matches using an empty
/// // string argument name
/// match m.subcommand() {
/// Some((external, ext_m)) => {
/// let ext_args: Vec<&std::ffi::OsStr> = ext_m.values_of_os("").unwrap().collect();
/// assert_eq!(external, "subcmd");
/// assert_eq!(ext_args, ["--option", "value", "-fff", "--flag"]);
/// },
/// _ => {},
/// }
/// ```
///
/// [`ArgMatches::values_of_os`]: crate::ArgMatches::values_of_os()
/// [`ArgMatches::values_of_lossy`]: crate::ArgMatches::values_of_lossy()
/// [`subcommands`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::allow_invalid_utf8_for_external_subcommands`] and [`App::is_allow_invalid_utf8_for_external_subcommands_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::allow_invalid_utf8_for_external_subcommands` and `App::is_allow_invalid_utf8_for_external_subcommands_set`"
)]
AllowInvalidUtf8ForExternalSubcommands,
/// Specifies that the help subcommand should print the long help message (`--help`).
@ -572,152 +198,36 @@ pub enum AppSettings {
/// [long format]: crate::App::long_about
UseLongFormatForHelpSubcommand,
/// Allows [`subcommands`] to override all requirements of the parent command.
///
/// For example, if you had a subcommand or top level application with a required argument
/// that is only required as long as there is no subcommand present,
/// using this setting would allow you to set those arguments to [`Arg::required(true)`]
/// and yet receive no error so long as the user uses a valid subcommand instead.
///
/// **NOTE:** This defaults to false (using subcommand does *not* negate requirements)
///
/// # Examples
///
/// This first example shows that it is an error to not use a required argument
///
/// ```rust
/// # use clap::{App, Arg, AppSettings, ErrorKind};
/// let err = App::new("myprog")
/// .setting(AppSettings::SubcommandsNegateReqs)
/// .arg(Arg::new("opt").required(true))
/// .subcommand(App::new("test"))
/// .try_get_matches_from(vec![
/// "myprog"
/// ]);
/// assert!(err.is_err());
/// assert_eq!(err.unwrap_err().kind(), ErrorKind::MissingRequiredArgument);
/// # ;
/// ```
///
/// This next example shows that it is no longer error to not use a required argument if a
/// valid subcommand is used.
///
/// ```rust
/// # use clap::{App, Arg, AppSettings, ErrorKind};
/// let noerr = App::new("myprog")
/// .setting(AppSettings::SubcommandsNegateReqs)
/// .arg(Arg::new("opt").required(true))
/// .subcommand(App::new("test"))
/// .try_get_matches_from(vec![
/// "myprog", "test"
/// ]);
/// assert!(noerr.is_ok());
/// # ;
/// ```
///
/// [`Arg::required(true)`]: crate::Arg::required()
/// [`subcommands`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::subcommand_negates_reqs`] and
/// [`App::is_subcommand_negates_reqs_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::subcommand_negates_reqs` and `App::is_subcommand_negates_reqs_set`"
)]
SubcommandsNegateReqs,
/// Specifies that use of an argument prevents the use of [`subcommands`].
///
/// By default `clap` allows arguments between subcommands such
/// as `<cmd> [cmd_args] <subcmd> [subcmd_args] <subsubcmd> [subsubcmd_args]`.
///
/// This setting disables that functionality and says that arguments can
/// only follow the *final* subcommand. For instance using this setting
/// makes only the following invocations possible:
///
/// * `<cmd> <subcmd> <subsubcmd> [subsubcmd_args]`
/// * `<cmd> <subcmd> [subcmd_args]`
/// * `<cmd> [cmd_args]`
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::ArgsNegateSubcommands);
/// ```
///
/// [`subcommands`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::args_conflicts_with_subcommands`] and
/// [`App::is_args_conflicts_with_subcommands_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::args_conflicts_with_subcommands` and `App::is_args_conflicts_with_subcommands_set`"
)]
ArgsNegateSubcommands,
/// Prevent subcommands from being consumed as an arguments value.
///
/// By default, if an option taking multiple values is followed by a subcommand, the
/// subcommand will be parsed as another value.
///
/// ```text
/// app --foo val1 val2 subcommand
/// --------- ----------
/// values another value
/// ```
///
/// This setting instructs the parser to stop when encountering a subcommand instead of
/// greedily consuming arguments.
///
/// ```text
/// app --foo val1 val2 subcommand
/// --------- ----------
/// values subcommand
/// ```
///
/// **Note:** Make sure you apply it as `global_setting` if you want this setting
/// to be propagated to subcommands and sub-subcommands!
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings, Arg};
/// let app = App::new("app").subcommand(App::new("sub")).arg(
/// Arg::new("arg")
/// .long("arg")
/// .multiple_values(true)
/// .takes_value(true),
/// );
///
/// let matches = app
/// .clone()
/// .try_get_matches_from(&["app", "--arg", "1", "2", "3", "sub"])
/// .unwrap();
///
/// assert_eq!(
/// matches.values_of("arg").unwrap().collect::<Vec<_>>(),
/// &["1", "2", "3", "sub"]
/// );
/// assert!(matches.subcommand_matches("sub").is_none());
///
/// let matches = app
/// .setting(AppSettings::SubcommandPrecedenceOverArg)
/// .try_get_matches_from(&["app", "--arg", "1", "2", "3", "sub"])
/// .unwrap();
///
/// assert_eq!(
/// matches.values_of("arg").unwrap().collect::<Vec<_>>(),
/// &["1", "2", "3"]
/// );
/// assert!(matches.subcommand_matches("sub").is_some());
/// ```
/// Deprecated, replaced with [`App::subcommand_precedence_over_arg`] and
/// [`App::is_subcommand_precedence_over_arg_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::subcommand_precedence_over_arg` and `App::is_subcommand_precedence_over_arg_set`"
)]
SubcommandPrecedenceOverArg,
/// Exit gracefully if no arguments are present (e.g. `$ myprog`).
///
/// **NOTE:** [`subcommands`] count as arguments
///
/// **NOTE:** Setting [`Arg::default_value`] effectively disables this option as it will
/// ensure that some argument is always present.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::ArgRequiredElseHelp);
/// ```
///
/// [`subcommands`]: crate::App::subcommand()
/// [`Arg::default_value`]: crate::Arg::default_value()
/// Deprecated, replaced with [`App::arg_required_else_help`] and
/// [`App::is_arg_required_else_help_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::arg_required_else_help` and `App::is_arg_required_else_help_set`"
)]
ArgRequiredElseHelp,
/// Displays the arguments and [`subcommands`] in the help message in the order that they were
@ -739,193 +249,80 @@ pub enum AppSettings {
/// [`App::display_order`]: crate::App::display_order
DeriveDisplayOrder,
/// Disables the automatic collapsing of positional args into `[ARGS]` inside the usage string.
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .global_setting(AppSettings::DontCollapseArgsInUsage)
/// .get_matches();
/// ```
/// Deprecated, replaced with [`App::dont_collapse_args_in_usage`] and
/// [`App::is_dont_collapse_args_in_usage_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::dont_collapse_args_in_usage` and `App::is_dont_collapse_args_in_usage_set`"
)]
DontCollapseArgsInUsage,
/// Places the help string for all arguments on the line after the argument.
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .global_setting(AppSettings::NextLineHelp)
/// .get_matches();
/// ```
/// Deprecated, replaced with [`App::next_line_help`] and [`App::is_next_line_help_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::next_line_help` and `App::is_next_line_help_set`"
)]
NextLineHelp,
/// Disables colorized help messages.
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::DisableColoredHelp)
/// .get_matches();
/// ```
/// Deprecated, replaced with [`App::disable_colored_help`] and
/// [`App::is_disable_colored_help_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::disable_colored_help` and `App::is_disable_colored_help_set`"
)]
DisableColoredHelp,
/// Disables `-h` and `--help` flag.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings, ErrorKind};
/// let res = App::new("myprog")
/// .setting(AppSettings::DisableHelpFlag)
/// .try_get_matches_from(vec![
/// "myprog", "-h"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// Deprecated, replaced with [`App::disable_help_flag`] and [`App::is_disable_help_flag_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::disable_help_flag` and `App::is_disable_help_flag_set`"
)]
DisableHelpFlag,
/// Disables the `help` [`subcommand`].
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings, ErrorKind, };
/// let res = App::new("myprog")
/// .setting(AppSettings::DisableHelpSubcommand)
/// // Normally, creating a subcommand causes a `help` subcommand to automatically
/// // be generated as well
/// .subcommand(App::new("test"))
/// .try_get_matches_from(vec![
/// "myprog", "help"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
///
/// [`subcommand`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::disable_help_subcommand`] and
/// [`App::is_disable_help_subcommand_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::disable_help_subcommand` and `App::is_disable_help_subcommand_set`"
)]
DisableHelpSubcommand,
/// Disables `-V` and `--version` flag.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, AppSettings, ErrorKind};
/// let res = App::new("myprog")
/// .setting(AppSettings::DisableVersionFlag)
/// .try_get_matches_from(vec![
/// "myprog", "-V"
/// ]);
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// Deprecated, replaced with [`App::disable_version_flag`] and
/// [`App::is_disable_version_flag_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::disable_version_flag` and `App::is_disable_version_flag_set`"
)]
DisableVersionFlag,
/// Specifies to use the version of the current command for all [`subcommands`].
///
/// Defaults to `false`; subcommands have independent version strings from their parents.
///
/// **Note:** Make sure you apply it as `global_setting` if you want this setting
/// to be propagated to subcommands and sub-subcommands!
///
/// # Examples
///
/// ```no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .version("v1.1")
/// .global_setting(AppSettings::PropagateVersion)
/// .subcommand(App::new("test"))
/// .get_matches();
/// // running `$ myprog test --version` will display
/// // "myprog-test v1.1"
/// ```
///
/// [`subcommands`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::propagate_version`] and [`App::is_propagate_version_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::propagate_version` and `App::is_propagate_version_set`"
)]
PropagateVersion,
/// Specifies that this [`subcommand`] should be hidden from help messages
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, AppSettings, };
/// App::new("myprog")
/// .subcommand(App::new("test")
/// .setting(AppSettings::Hidden))
/// # ;
/// ```
///
/// [`subcommand`]: crate::App::subcommand()
/// Deprecated, replaced with [`App::hide`] and [`App::is_hide_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::hide` and `App::is_hide_set`"
)]
Hidden,
/// Tells `clap` *not* to print possible values when displaying help information.
///
/// This can be useful if there are many values, or they are explained elsewhere.
///
/// To set this per argument, see
/// [`Arg::hide_possible_values`][crate::Arg::hide_possible_values].
/// Deprecated, replaced with [`App::hide_possible_values`] and
/// [`Arg::is_hide_possible_values_set`]
#[deprecated(
since = "3.1.0",
note = "Replaced with `App::hide_possible_values` and `Arg::is_hide_possible_values_set`"
)]
HidePossibleValues,
/// Panic if help descriptions are omitted.
///
/// **NOTE:** When deriving [`Parser`][crate::Parser], you could instead check this at
/// compile-time with `#![deny(missing_docs)]`
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .global_setting(AppSettings::HelpExpected)
/// .arg(
/// Arg::new("foo").help("It does foo stuff")
/// // As required via AppSettings::HelpExpected, a help message was supplied
/// )
/// # .get_matches();
/// ```
///
/// # Panics
///
/// ```rust,no_run
/// # use clap::{App, Arg, AppSettings};
/// App::new("myapp")
/// .global_setting(AppSettings::HelpExpected)
/// .arg(
/// Arg::new("foo")
/// // Someone forgot to put .about("...") here
/// // Since the setting AppSettings::HelpExpected is activated, this will lead to
/// // a panic (if you are in debug mode)
/// )
/// # .get_matches();
///```
/// Deprecated, replaced with [`App::help_expected`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::help_expected`")]
HelpExpected,
/// Specifies that the parser should not assume the first argument passed is the binary name.
///
/// This is normally the case when using a "daemon" style mode, or an interactive CLI where
/// one would not normally type the binary or program name for each command.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, arg, AppSettings};
/// let m = App::new("myprog")
/// .setting(AppSettings::NoBinaryName)
/// .arg(arg!(<cmd> ... "commands to run"))
/// .get_matches_from(vec!["command", "set"]);
///
/// let cmds: Vec<&str> = m.values_of("cmd").unwrap().collect();
/// assert_eq!(cmds, ["command", "set"]);
/// ```
/// [`try_get_matches_from_mut`]: crate::App::try_get_matches_from_mut()
/// Deprecated, replaced with [`App::no_binary_name`]
#[deprecated(since = "3.1.0", note = "Replaced with `App::no_binary_name`")]
NoBinaryName,
/// Treat the auto-generated `-h, --help` flags like any other flag, and *not* print the help

View file

@ -1,9 +1,9 @@
use crate::{App, AppSettings};
use crate::App;
#[test]
fn propagate_version() {
let mut app = App::new("test")
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.version("1.1")
.subcommand(App::new("sub1"));
app._propagate();
@ -13,7 +13,7 @@ fn propagate_version() {
#[test]
fn global_setting() {
let mut app = App::new("test")
.global_setting(AppSettings::AllowHyphenValues)
.disable_version_flag(true)
.subcommand(App::new("subcmd"));
app._propagate();
assert!(app
@ -21,28 +21,7 @@ fn global_setting() {
.iter()
.find(|s| s.name == "subcmd")
.unwrap()
.is_set(AppSettings::AllowHyphenValues));
}
#[test]
fn global_settings() {
let mut app = App::new("test")
.global_setting(AppSettings::AllowHyphenValues)
.global_setting(AppSettings::TrailingVarArg)
.subcommand(App::new("subcmd"));
app._propagate();
assert!(app
.subcommands
.iter()
.find(|s| s.name == "subcmd")
.unwrap()
.is_set(AppSettings::AllowHyphenValues));
assert!(app
.subcommands
.iter()
.find(|s| s.name == "subcmd")
.unwrap()
.is_set(AppSettings::TrailingVarArg));
.is_disable_version_flag_set());
}
// This test will *fail to compile* if App is not Send + Sync
@ -55,9 +34,9 @@ fn app_send_sync() {
#[test]
fn issue_2090() {
let mut app = App::new("app")
.global_setting(AppSettings::DisableVersionFlag)
.disable_version_flag(true)
.subcommand(App::new("sub"));
app._build();
assert!(app.subcommands[0].is_set(AppSettings::DisableVersionFlag));
assert!(app.subcommands[0].is_disable_version_flag_set());
}

View file

@ -472,7 +472,7 @@ impl<'help> Arg<'help> {
/// **NOTE:** This will change the usage string to look like `$ prog [OPTIONS] [-- <ARG>]` if
/// `ARG` is marked as `.last(true)`.
///
/// **NOTE:** This setting will imply [`crate::AppSettings::DontCollapseArgsInUsage`] because failing
/// **NOTE:** This setting will imply [`crate::App::dont_collapse_args_in_usage`] because failing
/// to set this can make the usage string very confusing.
///
/// **NOTE**: This setting only applies to positional arguments, and has no effect on OPTIONS

View file

@ -15,7 +15,7 @@ pub(crate) fn assert_app(app: &App) {
if app.version.is_none() && app.long_version.is_none() {
// PropagateVersion is meaningless if there is no version
assert!(
!app.settings.is_set(AppSettings::PropagateVersion),
!app.is_propagate_version_set(),
"App {}: No version information via App::version or App::long_version to propagate",
app.get_name(),
);
@ -215,7 +215,7 @@ pub(crate) fn assert_app(app: &App) {
);
assert!(
app.is_set(AppSettings::TrailingVarArg),
app.is_trailing_var_arg_set(),
"App {}: Positional argument '{}' has hint CommandWithArguments, so App must have TrailingVarArg set.",
app.get_name(),
arg.name
@ -291,7 +291,7 @@ pub(crate) fn assert_app(app: &App) {
);
}
app._panic_on_missing_help(app.g_settings.is_set(AppSettings::HelpExpected));
app._panic_on_missing_help(app.is_help_expected_set());
assert_app_flags(app);
}
@ -373,15 +373,13 @@ fn find_duplicates<T: PartialEq>(slice: &[T]) -> impl Iterator<Item = (&T, &T)>
}
fn assert_app_flags(app: &App) {
use AppSettings::*;
macro_rules! checker {
($a:ident requires $($b:ident)|+) => {
if app.is_set($a) {
if app.$a() {
let mut s = String::new();
$(
if !app.is_set($b) {
if !app.$b() {
s.push_str(&format!(" AppSettings::{} is required when AppSettings::{} is set.\n", std::stringify!($b), std::stringify!($a)));
}
)+
@ -392,11 +390,11 @@ fn assert_app_flags(app: &App) {
}
};
($a:ident conflicts $($b:ident)|+) => {
if app.is_set($a) {
if app.$a() {
let mut s = String::new();
$(
if app.is_set($b) {
if app.$b() {
s.push_str(&format!(" AppSettings::{} conflicts with AppSettings::{}.\n", std::stringify!($b), std::stringify!($a)));
}
)+
@ -408,9 +406,9 @@ fn assert_app_flags(app: &App) {
};
}
checker!(AllowInvalidUtf8ForExternalSubcommands requires AllowExternalSubcommands);
checker!(is_allow_invalid_utf8_for_external_subcommands_set requires is_allow_external_subcommands_set);
#[cfg(feature = "unstable-multicall")]
checker!(Multicall conflicts NoBinaryName);
checker!(is_multicall_set conflicts is_no_binary_name_set);
}
#[cfg(debug_assertions)]
@ -502,7 +500,7 @@ fn _verify_positionals(app: &App) -> bool {
let mut found = false;
if app.is_set(AppSettings::AllowMissingPositional) {
if app.is_allow_missing_positional_set() {
// Check that if a required positional argument is found, all positions with a lower
// index are also required.
let mut foundx2 = false;
@ -566,7 +564,7 @@ fn _verify_positionals(app: &App) -> bool {
.get_positionals()
.any(|p| p.is_last_set() && p.is_required_set())
&& app.has_subcommands()
&& !app.is_set(AppSettings::SubcommandsNegateReqs)
&& !app.is_subcommand_negates_reqs_set()
{
panic!(
"Having a required positional argument with .last(true) set *and* child \

View file

@ -9,7 +9,7 @@ use std::{
// Internal
use crate::{
build::{arg::display_arg_val, App, AppSettings, Arg},
build::{arg::display_arg_val, App, Arg},
output::{fmt::Colorizer, Usage},
};
@ -25,7 +25,6 @@ pub(crate) struct Help<'help, 'app, 'writer> {
app: &'app App<'help>,
usage: &'app Usage<'help, 'app>,
next_line_help: bool,
hide_pv: bool,
term_w: usize,
use_long: bool,
}
@ -65,15 +64,13 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> {
},
),
};
let next_line_help = app.is_set(AppSettings::NextLineHelp);
let hide_pv = app.is_set(AppSettings::HidePossibleValues);
let next_line_help = app.is_next_line_help_set();
Help {
writer,
app,
usage,
next_line_help,
hide_pv,
term_w,
use_long,
}
@ -571,7 +568,7 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> {
}
}
if !self.hide_pv && !a.is_hide_possible_values_set() && !a.possible_vals.is_empty() {
if !a.is_hide_possible_values_set() && !a.possible_vals.is_empty() {
debug!(
"Help::spec_vals: Found possible vals...{:?}",
a.possible_vals
@ -1005,7 +1002,7 @@ fn should_show_arg(use_long: bool, arg: &Arg) -> bool {
}
fn should_show_subcommand(subcommand: &App) -> bool {
!subcommand.is_set(AppSettings::Hidden)
!subcommand.is_hide_set()
}
fn text_wrapper(help: &str, width: usize) -> String {

View file

@ -64,7 +64,7 @@ impl<'help, 'app> Usage<'help, 'app> {
usage.push_str(" [OPTIONS]");
}
let allow_missing_positional = self.app.is_set(AS::AllowMissingPositional);
let allow_missing_positional = self.app.is_allow_missing_positional_set();
if !allow_missing_positional {
usage.push_str(&req_string);
}
@ -77,8 +77,7 @@ impl<'help, 'app> Usage<'help, 'app> {
.get_non_positionals()
.any(|o| o.is_multiple_values_set())
&& self.app.get_positionals().any(|p| !p.is_required_set())
&& !(self.app.has_visible_subcommands()
|| self.app.is_set(AS::AllowExternalSubcommands))
&& !(self.app.has_visible_subcommands() || self.app.is_allow_external_subcommands_set())
&& !has_last
{
usage.push_str(" [--]");
@ -121,14 +120,14 @@ impl<'help, 'app> Usage<'help, 'app> {
// incl_reqs is only false when this function is called recursively
if self.app.has_visible_subcommands() && incl_reqs
|| self.app.is_set(AS::AllowExternalSubcommands)
|| self.app.is_allow_external_subcommands_set()
{
let placeholder = self.app.subcommand_value_name.unwrap_or("SUBCOMMAND");
if self.app.is_set(AS::SubcommandsNegateReqs)
|| self.app.is_set(AS::ArgsNegateSubcommands)
if self.app.is_subcommand_negates_reqs_set()
|| self.app.is_args_conflicts_with_subcommands_set()
{
usage.push_str("\n ");
if !self.app.is_set(AS::ArgsNegateSubcommands) {
if !self.app.is_args_conflicts_with_subcommands_set() {
usage.push_str(&*self.create_help_usage(false));
} else {
usage.push_str(&*name);
@ -136,7 +135,7 @@ impl<'help, 'app> Usage<'help, 'app> {
usage.push_str(" <");
usage.push_str(placeholder);
usage.push('>');
} else if self.app.is_set(AS::SubcommandRequired)
} else if self.app.is_subcommand_required_set()
|| self.app.is_set(AS::SubcommandRequiredElseHelp)
{
usage.push_str(" <");
@ -173,7 +172,7 @@ impl<'help, 'app> Usage<'help, 'app> {
.unwrap_or(&self.app.name)[..],
);
usage.push_str(&*r_string);
if self.app.is_set(AS::SubcommandRequired) {
if self.app.is_subcommand_required_set() {
usage.push_str(" <");
usage.push_str(self.app.subcommand_value_name.unwrap_or("SUBCOMMAND"));
usage.push('>');
@ -211,7 +210,7 @@ impl<'help, 'app> Usage<'help, 'app> {
}
}
if !self.app.is_set(AS::DontCollapseArgsInUsage) && count > 1 {
if !self.app.is_dont_collapse_args_in_usage_set() && count > 1 {
debug!("Usage::get_args_tag:iter: More than one, returning [ARGS]");
// [ARGS]
@ -245,7 +244,7 @@ impl<'help, 'app> Usage<'help, 'app> {
pos.name_no_brackets(),
pos.multiple_str()
))
} else if self.app.is_set(AS::DontCollapseArgsInUsage)
} else if self.app.is_dont_collapse_args_in_usage_set()
&& self.app.has_positionals()
&& incl_reqs
{

View file

@ -30,7 +30,7 @@ impl ArgMatcher {
//
// See clap-rs/clap#3263
#[cfg(debug_assertions)]
disable_asserts: _app.is_set(crate::AppSettings::AllowExternalSubcommands),
disable_asserts: _app.is_allow_external_subcommands_set(),
..Default::default()
})
}

View file

@ -64,7 +64,7 @@ impl<'help, 'app> Parser<'help, 'app> {
// Should we color the help?
pub(crate) fn color_help(&self) -> ColorChoice {
#[cfg(feature = "color")]
if self.is_set(AS::DisableColoredHelp) {
if self.app.is_disable_colored_help_set() {
return ColorChoice::Never;
}
@ -139,7 +139,7 @@ impl<'help, 'app> Parser<'help, 'app> {
.last()
.map_or(false, |p_name| !p_name.is_last_set());
let missing_pos = self.is_set(AS::AllowMissingPositional)
let missing_pos = self.app.is_allow_missing_positional_set()
&& is_second_to_last
&& !trailing_values;
@ -181,7 +181,7 @@ impl<'help, 'app> Parser<'help, 'app> {
pos_counter
}
} else if trailing_values
&& (self.is_set(AS::AllowMissingPositional) || contains_last)
&& (self.app.is_allow_missing_positional_set() || contains_last)
{
// Came to -- and one positional has .last(true) set, so we go immediately
// to the last (highest index) positional
@ -194,7 +194,7 @@ impl<'help, 'app> Parser<'help, 'app> {
// Has the user already passed '--'? Meaning only positional args follow
if !trailing_values {
if self.is_set(AS::SubcommandPrecedenceOverArg)
if self.app.is_subcommand_precedence_over_arg_set()
|| !matches!(parse_state, ParseState::Opt(_) | ParseState::Pos(_))
{
// Does the arg match a subcommand name, or any of its aliases (if defined)
@ -203,7 +203,7 @@ impl<'help, 'app> Parser<'help, 'app> {
if let Some(sc_name) = sc_name {
if sc_name == "help"
&& !self.is_set(AS::NoAutoHelp)
&& !self.is_set(AS::DisableHelpSubcommand)
&& !self.app.is_disable_help_subcommand_set()
{
self.parse_help_subcommand(remaining_args)?;
}
@ -284,7 +284,7 @@ impl<'help, 'app> Parser<'help, 'app> {
} else if let Some(short_arg) = arg_os.strip_prefix("-") {
// Arg looks like a short flag, and not a possible number
// Try to parse short args like normal, if AllowHyphenValues or
// Try to parse short args like normal, if allow_hyphen_values or
// AllowNegativeNumbers is set, parse_short_arg will *not* throw
// an error, and instead return Ok(None)
let parse_result = self.parse_short_arg(
@ -396,7 +396,7 @@ impl<'help, 'app> Parser<'help, 'app> {
));
}
if self.is_set(AS::TrailingVarArg) && pos_counter == positional_count {
if self.app.is_trailing_var_arg_set() && pos_counter == positional_count {
trailing_values = true;
}
@ -426,7 +426,7 @@ impl<'help, 'app> Parser<'help, 'app> {
parse_state = ParseState::Pos(p.id.clone());
}
valid_arg_found = true;
} else if self.is_set(AS::AllowExternalSubcommands) {
} else if self.app.is_allow_external_subcommands_set() {
// Get external subcommand name
let sc_name = match arg_os.to_str() {
Some(s) => s.to_string(),
@ -442,8 +442,9 @@ impl<'help, 'app> Parser<'help, 'app> {
let mut sc_m = ArgMatcher::new(self.app);
while let Some((v, _)) = it.next() {
let allow_invalid_utf8 =
self.is_set(AS::AllowInvalidUtf8ForExternalSubcommands);
let allow_invalid_utf8 = self
.app
.is_allow_invalid_utf8_for_external_subcommands_set();
if !allow_invalid_utf8 && v.to_str().is_none() {
return Err(ClapError::invalid_utf8(
self.app,
@ -487,7 +488,7 @@ impl<'help, 'app> Parser<'help, 'app> {
.name
.clone();
self.parse_subcommand(&sc_name, matcher, it, keep_state)?;
} else if self.is_set(AS::SubcommandRequired) {
} else if self.app.is_subcommand_required_set() {
let bn = self.app.bin_name.as_ref().unwrap_or(&self.app.name);
return Err(ClapError::missing_subcommand(
self.app,
@ -541,7 +542,8 @@ impl<'help, 'app> Parser<'help, 'app> {
);
}
// If the argument must be a subcommand.
if !self.app.has_args() || self.is_set(AS::InferSubcommands) && self.app.has_subcommands() {
if !self.app.has_args() || self.app.is_infer_subcommands_set() && self.app.has_subcommands()
{
return ClapError::unrecognized_subcommand(
self.app,
arg_os.to_str_lossy().into_owned(),
@ -564,8 +566,8 @@ impl<'help, 'app> Parser<'help, 'app> {
fn possible_subcommand(&self, arg_os: &RawOsStr, valid_arg_found: bool) -> Option<&str> {
debug!("Parser::possible_subcommand: arg={:?}", arg_os);
if !(self.is_set(AS::ArgsNegateSubcommands) && valid_arg_found) {
if self.is_set(AS::InferSubcommands) {
if !(self.app.is_args_conflicts_with_subcommands_set() && valid_arg_found) {
if self.app.is_infer_subcommands_set() {
// For subcommand `test`, we accepts it's prefix: `t`, `te`,
// `tes` and `test`.
let v = self
@ -591,7 +593,7 @@ impl<'help, 'app> Parser<'help, 'app> {
// Checks if the arg matches a long flag subcommand name, or any of its aliases (if defined)
fn possible_long_flag_subcommand(&self, arg_os: &RawOsStr) -> Option<&str> {
debug!("Parser::possible_long_flag_subcommand: arg={:?}", arg_os);
if self.is_set(AS::InferSubcommands) {
if self.app.is_infer_subcommands_set() {
let options = self
.app
.get_subcommands()
@ -668,9 +670,10 @@ impl<'help, 'app> Parser<'help, 'app> {
next, current_positional.name
);
if self.is_set(AS::AllowHyphenValues)
if self.app.is_allow_hyphen_values_set()
|| self.app[&current_positional.id].is_allow_hyphen_values_set()
|| (self.is_set(AS::AllowNegativeNumbers) && next.to_str_lossy().parse::<f64>().is_ok())
|| (self.app.is_allow_negative_numbers_set()
&& next.to_str_lossy().parse::<f64>().is_ok())
{
// If allow hyphen, this isn't a new arg.
debug!("Parser::is_new_arg: Allow hyphen");
@ -702,7 +705,7 @@ impl<'help, 'app> Parser<'help, 'app> {
let mut mid_string = String::from(" ");
if !self.is_set(AS::SubcommandsNegateReqs) {
if !self.app.is_subcommand_negates_reqs_set() {
let reqs =
Usage::new(self.app, &self.required).get_required_usage_from(&[], None, true); // maybe Some(m)
@ -712,7 +715,7 @@ impl<'help, 'app> Parser<'help, 'app> {
}
}
let partial_parsing_enabled = self.is_set(AS::IgnoreErrors);
let partial_parsing_enabled = self.app.is_ignore_errors_set();
if let Some(sc) = self.app.subcommands.iter_mut().find(|s| s.name == sc_name) {
// Display subcommand name, short and long in usage
@ -795,7 +798,8 @@ impl<'help, 'app> Parser<'help, 'app> {
if let Some(help) = self.app.find(&Id::help_hash()) {
if let Some(h) = help.long {
if arg == h && !self.is_set(AS::NoAutoHelp) && !self.is_set(AS::DisableHelpFlag) {
if arg == h && !self.is_set(AS::NoAutoHelp) && !self.app.is_disable_help_flag_set()
{
debug!("Help");
return Some(ParseResult::HelpFlag);
}
@ -806,7 +810,7 @@ impl<'help, 'app> Parser<'help, 'app> {
if let Some(v) = version.long {
if arg == v
&& !self.is_set(AS::NoAutoVersion)
&& !self.is_set(AS::DisableVersionFlag)
&& !self.app.is_disable_version_flag_set()
{
debug!("Version");
return Some(ParseResult::VersionFlag);
@ -827,7 +831,8 @@ impl<'help, 'app> Parser<'help, 'app> {
if let Some(help) = self.app.find(&Id::help_hash()) {
if let Some(h) = help.short {
if arg == h && !self.is_set(AS::NoAutoHelp) && !self.is_set(AS::DisableHelpFlag) {
if arg == h && !self.is_set(AS::NoAutoHelp) && !self.app.is_disable_help_flag_set()
{
debug!("Help");
return Some(ParseResult::HelpFlag);
}
@ -838,7 +843,7 @@ impl<'help, 'app> Parser<'help, 'app> {
if let Some(v) = version.short {
if arg == v
&& !self.is_set(AS::NoAutoVersion)
&& !self.is_set(AS::DisableVersionFlag)
&& !self.app.is_disable_version_flag_set()
{
debug!("Version");
return Some(ParseResult::VersionFlag);
@ -908,7 +913,7 @@ impl<'help, 'app> Parser<'help, 'app> {
opt.to_string()
);
Some(opt)
} else if self.is_set(AS::InferLongArgs) {
} else if self.app.is_infer_long_args_set() {
let arg_str = arg.to_str_lossy();
self.app.args.args().find(|a| {
a.long.map_or(false, |long| long.starts_with(&*arg_str))
@ -954,7 +959,7 @@ impl<'help, 'app> Parser<'help, 'app> {
}
} else if let Some(sc_name) = self.possible_long_flag_subcommand(arg) {
ParseResult::FlagSubCommand(sc_name.to_string())
} else if self.is_set(AS::AllowHyphenValues) {
} else if self.app.is_allow_hyphen_values_set() {
ParseResult::MaybeHyphenValue
} else {
ParseResult::NoMatchingArg {
@ -977,10 +982,10 @@ impl<'help, 'app> Parser<'help, 'app> {
let arg = short_arg.to_str_lossy();
#[allow(clippy::blocks_in_if_conditions)]
if self.is_set(AS::AllowNegativeNumbers) && arg.parse::<f64>().is_ok() {
if self.app.is_allow_negative_numbers_set() && arg.parse::<f64>().is_ok() {
debug!("Parser::parse_short_arg: negative number");
return ParseResult::MaybeHyphenValue;
} else if self.is_set(AS::AllowHyphenValues)
} else if self.app.is_allow_hyphen_values_set()
&& arg.chars().any(|c| !self.app.contains_short(c))
{
debug!("Parser::parse_short_args: contains non-short flag");
@ -1167,9 +1172,9 @@ impl<'help, 'app> Parser<'help, 'app> {
debug!(
"Parser::add_val_to_arg; trailing_values={:?}, DontDelimTrailingVals={:?}",
trailing_values,
self.is_set(AS::DontDelimitTrailingValues)
self.app.is_dont_delimit_trailing_values_set()
);
if !(trailing_values && self.is_set(AS::DontDelimitTrailingValues)) {
if !(trailing_values && self.app.is_dont_delimit_trailing_values_set()) {
if let Some(delim) = arg.val_delim {
let terminator = arg.terminator.map(OsStr::new);
let vals = val

View file

@ -1,5 +1,5 @@
// Internal
use crate::build::{App, AppSettings as AS, Arg, ArgPredicate, PossibleValue};
use crate::build::{App, Arg, ArgPredicate, PossibleValue};
use crate::error::{Error, Result as ClapResult};
use crate::output::Usage;
use crate::parse::{ArgMatcher, MatchedArg, ParseState, Parser};
@ -60,13 +60,13 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
.count();
if num_user_values == 0
&& matcher.subcommand_name().is_none()
&& self.p.is_set(AS::ArgRequiredElseHelp)
&& self.p.app.is_arg_required_else_help_set()
{
let message = self.p.write_help_err()?;
return Err(Error::display_help_error(self.p.app, message));
}
self.validate_conflicts(matcher)?;
if !(self.p.is_set(AS::SubcommandsNegateReqs) && is_subcmd || reqs_validated) {
if !(self.p.app.is_subcommand_negates_reqs_set() && is_subcmd || reqs_validated) {
self.validate_required(matcher)?;
}
self.validate_matched_args(matcher)?;

View file

@ -129,45 +129,41 @@ SUBCOMMANDS:
#[test]
fn setting() {
let m = App::new("setting").setting(AppSettings::AllArgsOverrideSelf);
#![allow(deprecated)]
let m = App::new("setting").args_override_self(true);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf));
}
#[test]
fn global_setting() {
let m = App::new("global_setting").global_setting(AppSettings::AllArgsOverrideSelf);
#![allow(deprecated)]
let m = App::new("global_setting").args_override_self(true);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf));
}
#[test]
fn unset_setting() {
let m = App::new("unset_setting").setting(AppSettings::AllArgsOverrideSelf);
#![allow(deprecated)]
let m = App::new("unset_setting").args_override_self(true);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf));
let m = m.unset_setting(AppSettings::AllArgsOverrideSelf);
let m = m.args_override_self(false);
assert!(!m.is_set(AppSettings::AllArgsOverrideSelf), "{:#?}", m);
}
#[test]
fn unset_global_setting() {
let m = App::new("unset_global_setting").global_setting(AppSettings::AllArgsOverrideSelf);
#![allow(deprecated)]
let m = App::new("unset_global_setting").args_override_self(true);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf));
let m = m.unset_global_setting(AppSettings::AllArgsOverrideSelf);
let m = m.args_override_self(false);
assert!(!m.is_set(AppSettings::AllArgsOverrideSelf), "{:#?}", m);
}
#[test]
fn unset_on_global_setting() {
let m = App::new("unset_on_global_setting").global_setting(AppSettings::AllArgsOverrideSelf);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf));
let m = m.unset_setting(AppSettings::AllArgsOverrideSelf);
assert!(m.is_set(AppSettings::AllArgsOverrideSelf), "{:#?}", m);
}
#[test]
fn setting_bitor() {
#![allow(deprecated)]
let m = App::new("setting_bitor").setting(
AppSettings::InferSubcommands | AppSettings::Hidden | AppSettings::DisableHelpSubcommand,
);
@ -179,6 +175,7 @@ fn setting_bitor() {
#[test]
fn unset_setting_bitor() {
#![allow(deprecated)]
let m = App::new("unset_setting_bitor")
.setting(AppSettings::InferSubcommands)
.setting(AppSettings::Hidden)
@ -199,7 +196,7 @@ fn unset_setting_bitor() {
#[test]
fn sub_command_negate_required() {
App::new("sub_command_negate")
.setting(AppSettings::SubcommandsNegateReqs)
.subcommand_negates_reqs(true)
.arg(Arg::new("test").required(true).index(1))
.subcommand(App::new("sub1"))
.try_get_matches_from(vec!["myprog", "sub1"])
@ -209,7 +206,7 @@ fn sub_command_negate_required() {
#[test]
fn sub_command_negate_required_2() {
let result = App::new("sub_command_negate")
.setting(AppSettings::SubcommandsNegateReqs)
.subcommand_negates_reqs(true)
.arg(Arg::new("test").required(true).index(1))
.subcommand(App::new("sub1"))
.try_get_matches_from(vec![""]);
@ -221,7 +218,7 @@ fn sub_command_negate_required_2() {
#[test]
fn sub_command_required() {
let result = App::new("sc_required")
.setting(AppSettings::SubcommandRequired)
.subcommand_required(true)
.subcommand(App::new("sub1"))
.try_get_matches_from(vec![""]);
assert!(result.is_err());
@ -232,7 +229,7 @@ fn sub_command_required() {
#[test]
fn arg_required_else_help() {
let result = App::new("arg_required")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(Arg::new("test").index(1))
.try_get_matches_from(vec![""]);
@ -247,7 +244,7 @@ fn arg_required_else_help() {
#[test]
fn arg_required_else_help_over_reqs() {
let result = App::new("arg_required")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(Arg::new("test").index(1).required(true))
.try_get_matches_from(vec![""]);
@ -262,7 +259,7 @@ fn arg_required_else_help_over_reqs() {
#[test]
fn arg_required_else_help_with_default() {
let result = App::new("arg_required")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(arg!(--input <PATH>).required(false).default_value("-"))
.try_get_matches_from(vec![""]);
@ -277,7 +274,7 @@ fn arg_required_else_help_with_default() {
#[test]
fn arg_required_else_help_error_message() {
let app = App::new("test")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.version("1.0")
.arg(
Arg::new("info")
@ -326,7 +323,7 @@ fn subcommand_required_else_help_error_message() {
#[test]
fn infer_subcommands_fail_no_args() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
.try_get_matches_from(vec!["prog", "te"]);
@ -338,7 +335,7 @@ fn infer_subcommands_fail_no_args() {
#[test]
fn infer_subcommands_fail_no_args() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
.try_get_matches_from(vec!["prog", "te"]);
@ -349,7 +346,7 @@ fn infer_subcommands_fail_no_args() {
#[test]
fn infer_subcommands_fail_with_args() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.arg(Arg::new("some"))
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
@ -361,7 +358,7 @@ fn infer_subcommands_fail_with_args() {
#[test]
fn infer_subcommands_fail_with_args2() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.arg(Arg::new("some"))
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
@ -373,7 +370,7 @@ fn infer_subcommands_fail_with_args2() {
#[test]
fn infer_subcommands_pass() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.try_get_matches_from(vec!["prog", "te"])
.unwrap();
@ -383,7 +380,7 @@ fn infer_subcommands_pass() {
#[test]
fn infer_subcommands_pass_close() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
.try_get_matches_from(vec!["prog", "tes"])
@ -394,7 +391,7 @@ fn infer_subcommands_pass_close() {
#[test]
fn infer_subcommands_pass_exact_match() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("testa"))
.subcommand(App::new("testb"))
@ -407,7 +404,7 @@ fn infer_subcommands_pass_exact_match() {
#[test]
fn infer_subcommands_fail_suggestions() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
.try_get_matches_from(vec!["prog", "temps"]);
@ -419,7 +416,7 @@ fn infer_subcommands_fail_suggestions() {
#[test]
fn infer_subcommands_fail_suggestions() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test"))
.subcommand(App::new("temp"))
.try_get_matches_from(vec!["prog", "temps"]);
@ -430,7 +427,7 @@ fn infer_subcommands_fail_suggestions() {
#[test]
fn no_bin_name() {
let result = App::new("arg_required")
.setting(AppSettings::NoBinaryName)
.no_binary_name(true)
.arg(Arg::new("test").required(true).index(1))
.try_get_matches_from(vec!["testing"]);
assert!(result.is_ok(), "{}", result.unwrap_err());
@ -444,7 +441,7 @@ fn skip_possible_values() {
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.setting(AppSettings::HidePossibleValues)
.hide_possible_values(true)
.args(&[
arg!(-o --opt <opt> "some option")
.required(false)
@ -463,7 +460,7 @@ fn skip_possible_values() {
#[test]
fn stop_delim_values_only_pos_follows() {
let r = App::new("onlypos")
.setting(AppSettings::DontDelimitTrailingValues)
.dont_delimit_trailing_values(true)
.args(&[
arg!(f: -f <flag> "some opt").required(false),
arg!([arg] ... "some arg"),
@ -482,8 +479,8 @@ fn stop_delim_values_only_pos_follows() {
#[test]
fn dont_delim_values_trailingvararg() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.setting(AppSettings::DontDelimitTrailingValues)
.trailing_var_arg(true)
.dont_delimit_trailing_values(true)
.arg(arg!([opt] ... "some pos"))
.try_get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"])
.unwrap();
@ -512,7 +509,7 @@ fn delim_values_only_pos_follows() {
#[test]
fn delim_values_trailingvararg() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(arg!([opt] ... "some pos"))
.try_get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"])
.unwrap();
@ -544,7 +541,7 @@ fn delim_values_only_pos_follows_with_delim() {
#[test]
fn delim_values_trailingvararg_with_delim() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(arg!([opt] ... "some pos").use_value_delimiter(true))
.try_get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"])
.unwrap();
@ -558,7 +555,7 @@ fn delim_values_trailingvararg_with_delim() {
#[test]
fn leading_hyphen_short() {
let res = App::new("leadhy")
.setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(Arg::new("some"))
.arg(Arg::new("other").short('o'))
.try_get_matches_from(vec!["", "-bar", "-o"]);
@ -572,7 +569,7 @@ fn leading_hyphen_short() {
#[test]
fn leading_hyphen_long() {
let res = App::new("leadhy")
.setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(Arg::new("some"))
.arg(Arg::new("other").short('o'))
.try_get_matches_from(vec!["", "--bar", "-o"]);
@ -586,7 +583,7 @@ fn leading_hyphen_long() {
#[test]
fn leading_hyphen_opt() {
let res = App::new("leadhy")
.setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(Arg::new("some").takes_value(true).long("opt"))
.arg(Arg::new("other").short('o'))
.try_get_matches_from(vec!["", "--opt", "--bar", "-o"]);
@ -600,7 +597,7 @@ fn leading_hyphen_opt() {
#[test]
fn allow_negative_numbers() {
let res = App::new("negnum")
.setting(AppSettings::AllowNegativeNumbers)
.allow_negative_numbers(true)
.arg(Arg::new("panum"))
.arg(Arg::new("onum").short('o').takes_value(true))
.try_get_matches_from(vec!["negnum", "-20", "-o", "-1.2"]);
@ -613,7 +610,7 @@ fn allow_negative_numbers() {
#[test]
fn allow_negative_numbers_fail() {
let res = App::new("negnum")
.setting(AppSettings::AllowNegativeNumbers)
.allow_negative_numbers(true)
.arg(Arg::new("panum"))
.arg(Arg::new("onum").short('o').takes_value(true))
.try_get_matches_from(vec!["negnum", "--foo", "-o", "-1.2"]);
@ -624,8 +621,8 @@ fn allow_negative_numbers_fail() {
#[test]
fn leading_double_hyphen_trailingvararg() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.setting(AppSettings::AllowHyphenValues)
.trailing_var_arg(true)
.allow_hyphen_values(true)
.arg(arg!([opt] ... "some pos"))
.try_get_matches_from(vec!["", "--foo", "-Wl", "bar"])
.unwrap();
@ -639,7 +636,7 @@ fn leading_double_hyphen_trailingvararg() {
#[test]
fn disable_help_subcommand() {
let result = App::new("disablehelp")
.setting(AppSettings::DisableHelpSubcommand)
.disable_help_subcommand(true)
.subcommand(App::new("sub1"))
.try_get_matches_from(vec!["", "help"]);
assert!(result.is_err());
@ -651,7 +648,7 @@ fn disable_help_subcommand() {
fn dont_collapse_args() {
let app = App::new("clap-test")
.version("v1.4.8")
.setting(AppSettings::DontCollapseArgsInUsage)
.dont_collapse_args_in_usage(true)
.args(&[
Arg::new("arg1").help("some"),
Arg::new("arg2").help("some"),
@ -687,8 +684,8 @@ fn require_eq() {
#[test]
fn args_negate_subcommands_one_level() {
let res = App::new("disablehelp")
.setting(AppSettings::ArgsNegateSubcommands)
.setting(AppSettings::SubcommandsNegateReqs)
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(App::new("sub1").subcommand(App::new("sub2").subcommand(App::new("sub3"))))
@ -701,12 +698,14 @@ fn args_negate_subcommands_one_level() {
#[test]
fn args_negate_subcommands_two_levels() {
let res = App::new("disablehelp")
.global_setting(AppSettings::ArgsNegateSubcommands)
.global_setting(AppSettings::SubcommandsNegateReqs)
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg1> "some arg"))
.arg(arg!(<arg2> "some arg"))
.subcommand(
App::new("sub1")
.args_conflicts_with_subcommands(true)
.subcommand_negates_reqs(true)
.arg(arg!(<arg> "some"))
.arg(arg!(<arg2> "some"))
.subcommand(App::new("sub2").subcommand(App::new("sub3"))),
@ -736,7 +735,7 @@ fn propagate_vals_down() {
#[test]
fn allow_missing_positional() {
let m = App::new("test")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([src] "some file").default_value("src"))
.arg(arg!(<dest> "some file"))
.try_get_matches_from(vec!["test", "file"]);
@ -749,7 +748,7 @@ fn allow_missing_positional() {
#[test]
fn allow_missing_positional_no_default() {
let m = App::new("test")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([src] "some file"))
.arg(arg!(<dest> "some file"))
.try_get_matches_from(vec!["test", "file"]);
@ -762,7 +761,7 @@ fn allow_missing_positional_no_default() {
#[test]
fn missing_positional_no_hyphen() {
let r = App::new("bench")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([BENCH] "some bench"))
.arg(arg!([ARGS] ... "some args"))
.try_get_matches_from(vec!["bench", "foo", "arg1", "arg2", "arg3"]);
@ -783,7 +782,7 @@ fn missing_positional_no_hyphen() {
#[test]
fn missing_positional_hyphen() {
let r = App::new("bench")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([BENCH] "some bench"))
.arg(arg!([ARGS] ... "some args"))
.try_get_matches_from(vec!["bench", "--", "arg1", "arg2", "arg3"]);
@ -804,7 +803,7 @@ fn missing_positional_hyphen() {
#[test]
fn missing_positional_hyphen_far_back() {
let r = App::new("bench")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([BENCH1] "some bench"))
.arg(arg!([BENCH2] "some bench"))
.arg(arg!([BENCH3] "some bench"))
@ -831,7 +830,7 @@ fn missing_positional_hyphen_far_back() {
#[test]
fn missing_positional_hyphen_req_error() {
let r = App::new("bench")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(arg!([BENCH1] "some bench"))
.arg(arg!(<BENCH2> "some bench"))
.arg(arg!([ARGS] ... "some args"))
@ -843,7 +842,7 @@ fn missing_positional_hyphen_req_error() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args() {
let res = App::new("prog")
.global_setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(arg!(--"some-argument"))
.try_get_matches_from(vec!["prog", "hello"]);
@ -854,7 +853,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() {
let res = App::new("prog")
.global_setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(arg!(--"some-argument"))
.try_get_matches_from(vec!["prog", "--hello"]);
@ -865,7 +864,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() {
#[test]
fn issue_1066_allow_leading_hyphen_and_unknown_args_option() {
let res = App::new("prog")
.global_setting(AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(arg!(--"some-argument" <val>))
.try_get_matches_from(vec!["prog", "-hello"]);
@ -891,7 +890,7 @@ fn issue_1437_allow_hyphen_values_for_positional_arg() {
fn issue_1093_allow_ext_sc() {
let app = App::new("clap-test")
.version("v1.4.8")
.setting(AppSettings::AllowExternalSubcommands);
.allow_external_subcommands(true);
assert!(utils::compare_output(
app,
"clap-test --help",
@ -904,9 +903,9 @@ fn issue_1093_allow_ext_sc() {
fn allow_ext_sc_when_sc_required() {
let res = App::new("clap-test")
.version("v1.4.8")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.setting(AppSettings::SubcommandRequiredElseHelp)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.subcommand_required(true)
.try_get_matches_from(vec!["clap-test", "external-cmd", "foo"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -924,8 +923,8 @@ fn allow_ext_sc_when_sc_required() {
fn external_subcommand_looks_like_built_in() {
let res = App::new("cargo")
.version("1.26.0")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.subcommand(App::new("install"))
.try_get_matches_from(vec!["cargo", "install-update", "foo"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -943,7 +942,7 @@ fn external_subcommand_looks_like_built_in() {
fn aaos_flags() {
// flags
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--flag "some flag"))
.try_get_matches_from(vec!["", "--flag", "--flag"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -956,7 +955,7 @@ fn aaos_flags() {
fn aaos_flags_mult() {
// flags with multiple
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--flag ... "some flag"))
.try_get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -969,7 +968,7 @@ fn aaos_flags_mult() {
fn aaos_opts() {
// opts
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--opt <val> "some option"))
.try_get_matches_from(vec!["", "--opt=some", "--opt=other"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -983,7 +982,7 @@ fn aaos_opts() {
fn aaos_opts_w_other_overrides() {
// opts with other overrides
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--opt <val> "some option").required(false))
.arg(
arg!(--other <val> "some other option")
@ -1003,7 +1002,7 @@ fn aaos_opts_w_other_overrides() {
fn aaos_opts_w_other_overrides_rev() {
// opts with other overrides, rev
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--opt <val> "some option").required(true))
.arg(
arg!(--other <val> "some other option")
@ -1022,7 +1021,7 @@ fn aaos_opts_w_other_overrides_rev() {
fn aaos_opts_w_other_overrides_2() {
// opts with other overrides
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(
arg!(--opt <val> "some option")
.required(false)
@ -1042,7 +1041,7 @@ fn aaos_opts_w_other_overrides_2() {
fn aaos_opts_w_other_overrides_rev_2() {
// opts with other overrides, rev
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(
arg!(--opt <val> "some option")
.required(true)
@ -1061,7 +1060,7 @@ fn aaos_opts_w_other_overrides_rev_2() {
fn aaos_opts_mult() {
// opts with multiple
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(
arg!(--opt <val> ... "some option")
.number_of_values(1)
@ -1084,7 +1083,7 @@ fn aaos_opts_mult() {
fn aaos_opts_mult_req_delims() {
// opts with multiple and require delims
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--opt <val> ... "some option").multiple_values(true))
.try_get_matches_from(vec![
"",
@ -1110,7 +1109,7 @@ fn aaos_opts_mult_req_delims() {
fn aaos_pos_mult() {
// opts with multiple
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!([val] ... "some pos"))
.try_get_matches_from(vec!["", "some", "other", "value"]);
assert!(res.is_ok(), "{}", res.unwrap_err());
@ -1126,7 +1125,7 @@ fn aaos_pos_mult() {
#[test]
fn aaos_option_use_delim_false() {
let m = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(arg!(--opt <val> "some option").use_value_delimiter(false))
.try_get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"])
.unwrap();

View file

@ -1,6 +1,6 @@
use crate::utils;
use clap::{arg, error::ErrorKind, App, AppSettings, Arg};
use clap::{arg, error::ErrorKind, App, Arg};
#[test]
fn flag_subcommand_normal() {
@ -395,7 +395,7 @@ fn flag_subcommand_conflict_with_version() {
#[test]
fn flag_subcommand_long_infer_pass() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test").long_flag("test"))
.try_get_matches_from(vec!["prog", "--te"])
.unwrap();
@ -406,7 +406,7 @@ fn flag_subcommand_long_infer_pass() {
#[test]
fn flag_subcommand_long_infer_fail() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test").long_flag("test"))
.subcommand(App::new("temp").long_flag("temp"))
.try_get_matches_from(vec!["prog", "--te"]);
@ -418,7 +418,7 @@ fn flag_subcommand_long_infer_fail() {
#[test]
fn flag_subcommand_long_infer_fail() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test").long_flag("test"))
.subcommand(App::new("temp").long_flag("temp"))
.try_get_matches_from(vec!["prog", "--te"]);
@ -429,7 +429,7 @@ fn flag_subcommand_long_infer_fail() {
#[test]
fn flag_subcommand_long_infer_pass_close() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test").long_flag("test"))
.subcommand(App::new("temp").long_flag("temp"))
.try_get_matches_from(vec!["prog", "--tes"])
@ -440,7 +440,7 @@ fn flag_subcommand_long_infer_pass_close() {
#[test]
fn flag_subcommand_long_infer_exact_match() {
let m = App::new("prog")
.setting(AppSettings::InferSubcommands)
.infer_subcommands(true)
.subcommand(App::new("test").long_flag("test"))
.subcommand(App::new("testa").long_flag("testa"))
.subcommand(App::new("testb").long_flag("testb"))
@ -466,7 +466,7 @@ fn flag_subcommand_long_short_normal_usage_string() {
let app = App::new("pacman")
.about("package manager utility")
.version("5.2.1")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand_required(true)
.author("Pacman Development Team")
// Query subcommand
//
@ -520,7 +520,7 @@ fn flag_subcommand_long_normal_usage_string() {
let app = App::new("pacman")
.about("package manager utility")
.version("5.2.1")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand_required(true)
.author("Pacman Development Team")
// Query subcommand
//
@ -573,7 +573,7 @@ fn flag_subcommand_short_normal_usage_string() {
let app = App::new("pacman")
.about("package manager utility")
.version("5.2.1")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand_required(true)
.author("Pacman Development Team")
// Query subcommand
//

View file

@ -1,6 +1,6 @@
#![cfg(feature = "unstable-grouped")]
use clap::{App, AppSettings, Arg};
use clap::{App, Arg};
#[test]
fn grouped_value_works() {
@ -201,7 +201,7 @@ fn issue_1374() {
#[test]
fn issue_2171() {
let schema = App::new("ripgrep#1701 reproducer")
.setting(AppSettings::AllArgsOverrideSelf)
.args_override_self(true)
.arg(Arg::new("pretty").short('p').long("pretty"))
.arg(Arg::new("search_zip").short('z').long("search-zip"));

View file

@ -1,6 +1,6 @@
use crate::utils;
use clap::{arg, error::ErrorKind, App, AppSettings, Arg, ArgGroup, PossibleValue};
use clap::{arg, error::ErrorKind, App, Arg, ArgGroup, PossibleValue};
static REQUIRE_DELIM_HELP: &str = "test 1.3
Kevin K.
@ -684,7 +684,7 @@ fn req_last_arg_usage() {
fn args_with_last_usage() {
let app = App::new("flamegraph")
.version("0.1")
.setting(AppSettings::TrailingVarArg)
.trailing_var_arg(true)
.arg(
Arg::new("verbose")
.help("Prints out more stuff.")
@ -1182,7 +1182,7 @@ fn issue_688_hide_pos_vals() {
let app1 = App::new("ctest")
.version("0.1")
.term_width(120)
.setting(AppSettings::HidePossibleValues)
.hide_possible_values(true)
.arg(Arg::new("filter")
.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
@ -1383,7 +1383,7 @@ OPTIONS:
fn sc_negates_reqs() {
let app = App::new("prog")
.version("1.0")
.setting(AppSettings::SubcommandsNegateReqs)
.subcommand_negates_reqs(true)
.arg(arg!(-o --opt <FILE> "tests options"))
.arg(Arg::new("PATH").help("help"))
.subcommand(App::new("test"));
@ -1414,7 +1414,7 @@ fn hide_args() {
fn args_negate_sc() {
let app = App::new("prog")
.version("1.0")
.setting(AppSettings::ArgsNegateSubcommands)
.args_conflicts_with_subcommands(true)
.arg(arg!(-f --flag "testing flags"))
.arg(arg!(-o --opt <FILE> "tests options").required(false))
.arg(Arg::new("PATH").help("help"))
@ -1434,7 +1434,7 @@ fn issue_1046_hide_scs() {
.arg(arg!(-f --flag "testing flags"))
.arg(arg!(-o --opt <FILE> "tests options").required(false))
.arg(Arg::new("PATH").help("some"))
.subcommand(App::new("test").setting(AppSettings::Hidden));
.subcommand(App::new("test").hide(true));
assert!(utils::compare_output(
app,
"prog --help",
@ -1607,7 +1607,7 @@ fn last_arg_mult_usage_req() {
fn last_arg_mult_usage_req_with_sc() {
let app = App::new("last")
.version("0.1")
.setting(AppSettings::SubcommandsNegateReqs)
.subcommand_negates_reqs(true)
.arg(Arg::new("TARGET").required(true).help("some"))
.arg(Arg::new("CORPUS").help("some"))
.arg(
@ -1631,7 +1631,7 @@ fn last_arg_mult_usage_req_with_sc() {
fn last_arg_mult_usage_with_sc() {
let app = App::new("last")
.version("0.1")
.setting(AppSettings::ArgsNegateSubcommands)
.args_conflicts_with_subcommands(true)
.arg(Arg::new("TARGET").required(true).help("some"))
.arg(Arg::new("CORPUS").help("some"))
.arg(
@ -2042,7 +2042,7 @@ fn issue_1487() {
#[should_panic = "AppSettings::HelpExpected is enabled for the App"]
fn help_required_but_not_given() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo"))
.try_get_matches_from(empty_args())
.unwrap();
@ -2054,7 +2054,7 @@ fn help_required_but_not_given() {
fn help_required_but_not_given_settings_after_args() {
App::new("myapp")
.arg(Arg::new("foo"))
.setting(AppSettings::HelpExpected)
.help_expected(true)
.try_get_matches_from(empty_args())
.unwrap();
}
@ -2064,7 +2064,7 @@ fn help_required_but_not_given_settings_after_args() {
#[should_panic = "AppSettings::HelpExpected is enabled for the App"]
fn help_required_but_not_given_for_one_of_two_arguments() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo"))
.arg(Arg::new("bar").help("It does bar stuff"))
.try_get_matches_from(empty_args())
@ -2072,9 +2072,10 @@ fn help_required_but_not_given_for_one_of_two_arguments() {
}
#[test]
fn help_required_locally_but_not_given_for_subcommand() {
#[should_panic = "List of such arguments: delete"]
fn help_required_globally() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo").help("It does foo stuff"))
.subcommand(
App::new("bar")
@ -2090,7 +2091,7 @@ fn help_required_locally_but_not_given_for_subcommand() {
#[should_panic = "AppSettings::HelpExpected is enabled for the App"]
fn help_required_globally_but_not_given_for_subcommand() {
App::new("myapp")
.global_setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo").help("It does foo stuff"))
.subcommand(
App::new("bar")
@ -2104,7 +2105,7 @@ fn help_required_globally_but_not_given_for_subcommand() {
#[test]
fn help_required_and_given_for_subcommand() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo").help("It does foo stuff"))
.subcommand(
App::new("bar")
@ -2118,7 +2119,7 @@ fn help_required_and_given_for_subcommand() {
#[test]
fn help_required_and_given() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.arg(Arg::new("foo").help("It does foo stuff"))
.try_get_matches_from(empty_args())
.unwrap();
@ -2127,7 +2128,7 @@ fn help_required_and_given() {
#[test]
fn help_required_and_no_args() {
App::new("myapp")
.setting(AppSettings::HelpExpected)
.help_expected(true)
.try_get_matches_from(empty_args())
.unwrap();
}
@ -2155,8 +2156,8 @@ This is after help.
fn after_help_no_args() {
let mut app = App::new("myapp")
.version("1.0")
.setting(AppSettings::DisableHelpFlag)
.setting(AppSettings::DisableVersionFlag)
.disable_help_flag(true)
.disable_version_flag(true)
.after_help("This is after help.");
let help = {
@ -2416,7 +2417,7 @@ NETWORKING:
fn only_custom_heading_opts_no_args() {
let app = App::new("test")
.version("1.4")
.setting(AppSettings::DisableVersionFlag)
.disable_version_flag(true)
.mut_arg("help", |a| a.hide(true))
.next_help_heading(Some("NETWORKING"))
.arg(arg!(-s --speed <SPEED> "How fast").required(false));
@ -2442,7 +2443,7 @@ NETWORKING:
fn only_custom_heading_pos_no_args() {
let app = App::new("test")
.version("1.4")
.setting(AppSettings::DisableVersionFlag)
.disable_version_flag(true)
.mut_arg("help", |a| a.hide(true))
.next_help_heading(Some("NETWORKING"))
.arg(Arg::new("speed").help("How fast"));
@ -2485,7 +2486,7 @@ OPTIONS:
#[test]
fn missing_positional_final_required() {
let app = App::new("test")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(Arg::new("arg1"))
.arg(Arg::new("arg2").required(true));
assert!(utils::compare_output(
@ -2510,7 +2511,7 @@ OPTIONS:
#[test]
fn missing_positional_final_multiple() {
let app = App::new("test")
.setting(AppSettings::AllowMissingPositional)
.allow_missing_positional(true)
.arg(Arg::new("foo"))
.arg(Arg::new("bar"))
.arg(Arg::new("baz").takes_value(true).multiple_values(true));
@ -2638,7 +2639,7 @@ OPTIONS:
fn disabled_help_flag() {
let res = App::new("foo")
.subcommand(App::new("sub"))
.setting(AppSettings::DisableHelpFlag)
.disable_help_flag(true)
.try_get_matches_from("foo a".split(' '));
assert!(res.is_err());
let err = res.unwrap_err();
@ -2649,8 +2650,8 @@ fn disabled_help_flag() {
fn disabled_help_flag_and_subcommand() {
let res = App::new("foo")
.subcommand(App::new("sub"))
.setting(AppSettings::DisableHelpFlag)
.setting(AppSettings::DisableHelpSubcommand)
.disable_help_flag(true)
.disable_help_subcommand(true)
.try_get_matches_from("foo help".split(' '));
assert!(res.is_err());
let err = res.unwrap_err();
@ -2667,7 +2668,7 @@ fn override_help_subcommand() {
let app = App::new("bar")
.subcommand(App::new("help").arg(Arg::new("arg").takes_value(true)))
.subcommand(App::new("not_help").arg(Arg::new("arg").takes_value(true)))
.setting(AppSettings::DisableHelpSubcommand);
.disable_help_subcommand(true);
let matches = app.try_get_matches_from(&["bar", "help", "foo"]).unwrap();
assert_eq!(
matches.subcommand_matches("help").unwrap().value_of("arg"),
@ -2679,7 +2680,7 @@ fn override_help_subcommand() {
fn override_help_flag_using_long() {
let app = App::new("foo")
.subcommand(App::new("help").long_flag("help"))
.setting(AppSettings::DisableHelpFlag);
.disable_help_flag(true);
let matches = app.try_get_matches_from(&["foo", "--help"]).unwrap();
assert!(matches.subcommand_matches("help").is_some());
}
@ -2687,7 +2688,7 @@ fn override_help_flag_using_long() {
#[test]
fn override_help_flag_using_short() {
let app = App::new("foo")
.setting(AppSettings::DisableHelpFlag)
.disable_help_flag(true)
.subcommand(App::new("help").short_flag('h'));
let matches = app.try_get_matches_from(&["foo", "-h"]).unwrap();
assert!(matches.subcommand_matches("help").is_some());
@ -2718,7 +2719,7 @@ ARGS:
#[test]
fn disable_help_flag_affects_help_subcommand() {
let mut app = App::new("test_app")
.global_setting(AppSettings::DisableHelpFlag)
.disable_help_flag(true)
.subcommand(App::new("test").about("Subcommand"));
app._build_all();
@ -2739,7 +2740,7 @@ fn disable_help_flag_affects_help_subcommand() {
fn dont_propagate_version_to_help_subcommand() {
let app = clap::App::new("test")
.version("1.0")
.global_setting(clap::AppSettings::PropagateVersion)
.propagate_version(true)
.subcommand(clap::App::new("subcommand"));
assert!(utils::compare_output(

View file

@ -1,6 +1,6 @@
use crate::utils;
use clap::{arg, App, AppSettings, Arg};
use clap::{arg, App, Arg};
static HIDDEN_ARGS: &str = "test 1.4
Kevin K.
@ -250,7 +250,7 @@ OPTIONS:
fn hide_subcmds() {
let app = App::new("test")
.version("1.4")
.subcommand(App::new("sub").setting(AppSettings::Hidden));
.subcommand(App::new("sub").hide(true));
assert!(utils::compare_output(
app,
@ -329,7 +329,7 @@ fn hide_subcmds_only() {
.after_help("After help")
.mut_arg("help", |a| a.hide(true))
.mut_arg("version", |a| a.hide(true))
.subcommand(App::new("sub").setting(AppSettings::Hidden));
.subcommand(App::new("sub").hide(true));
assert!(utils::compare_output(
app,

View file

@ -1,8 +1,8 @@
use clap::{arg, App, AppSettings, Arg};
use clap::{arg, App, Arg};
#[test]
fn single_short_arg_without_value() {
let app = App::new("app").setting(AppSettings::IgnoreErrors).arg(arg!(
let app = App::new("app").ignore_errors(true).arg(arg!(
-c --config [FILE] "Sets a custom config file"
));
@ -15,7 +15,7 @@ fn single_short_arg_without_value() {
#[test]
fn single_long_arg_without_value() {
let app = App::new("app").setting(AppSettings::IgnoreErrors).arg(arg!(
let app = App::new("app").ignore_errors(true).arg(arg!(
-c --config [FILE] "Sets a custom config file"
));
@ -29,7 +29,7 @@ fn single_long_arg_without_value() {
#[test]
fn multiple_args_and_final_arg_without_value() {
let app = App::new("app")
.setting(AppSettings::IgnoreErrors)
.ignore_errors(true)
.arg(arg!(
-c --config [FILE] "Sets a custom config file"
))
@ -52,7 +52,7 @@ fn multiple_args_and_final_arg_without_value() {
#[test]
fn multiple_args_and_intermittent_arg_without_value() {
let app = App::new("app")
.setting(AppSettings::IgnoreErrors)
.ignore_errors(true)
.arg(arg!(
-c --config[FILE] "Sets a custom config file"
))
@ -76,7 +76,7 @@ fn multiple_args_and_intermittent_arg_without_value() {
#[test]
fn subcommand() {
let app = App::new("test")
.setting(AppSettings::IgnoreErrors)
.ignore_errors(true)
.subcommand(
App::new("some")
.arg(

View file

@ -1,6 +1,6 @@
use crate::utils;
use clap::{arg, error::ErrorKind, App, AppSettings, Arg, ArgMatches};
use clap::{arg, error::ErrorKind, App, Arg, ArgMatches};
#[cfg(feature = "suggestions")]
static DYM: &str =
@ -589,7 +589,7 @@ fn issue_2279() {
#[test]
fn infer_long_arg() {
let app = App::new("test")
.setting(AppSettings::InferLongArgs)
.infer_long_args(true)
.arg(Arg::new("racetrack").long("racetrack").alias("autobahn"))
.arg(Arg::new("racecar").long("racecar").takes_value(true));
@ -615,7 +615,7 @@ fn infer_long_arg() {
assert_eq!(matches.value_of("racecar"), None);
let app = App::new("test")
.setting(AppSettings::InferLongArgs)
.infer_long_args(true)
.arg(Arg::new("arg").long("arg"));
let matches = app.clone().try_get_matches_from(&["test", "--"]).unwrap();

View file

@ -15,7 +15,7 @@ fn only_pos_follow() {
#[test]
fn issue_946() {
let r = App::new("compiletest")
.setting(clap::AppSettings::AllowHyphenValues)
.allow_hyphen_values(true)
.arg(arg!(--exact "filters match exactly"))
.arg(
clap::Arg::new("filter")

View file

@ -1,6 +1,6 @@
use crate::utils;
use clap::{arg, error::ErrorKind, App, AppSettings, Arg};
use clap::{arg, error::ErrorKind, App, Arg};
static VISIBLE_ALIAS_HELP: &str = "clap-test 2.6
@ -506,8 +506,8 @@ fn issue_2494_subcommand_is_present() {
fn subcommand_not_recognized() {
let app = App::new("fake")
.subcommand(App::new("sub"))
.setting(AppSettings::DisableHelpSubcommand)
.setting(AppSettings::InferSubcommands);
.disable_help_subcommand(true)
.infer_subcommands(true);
assert!(utils::compare_output(
app,
"fake help",
@ -529,7 +529,7 @@ fn busybox_like_multicall() {
[App::new("true"), App::new("false")]
}
let app = App::new("busybox")
.setting(AppSettings::Multicall)
.multicall(true)
.subcommand(App::new("busybox").subcommands(applet_commands()))
.subcommands(applet_commands());
@ -552,7 +552,7 @@ fn busybox_like_multicall() {
#[test]
fn hostname_like_multicall() {
let mut app = App::new("hostname")
.setting(AppSettings::Multicall)
.multicall(true)
.subcommand(App::new("hostname"))
.subcommand(App::new("dnsdomainname"));

View file

@ -1,6 +1,6 @@
#![cfg(not(windows))]
use clap::{arg, error::ErrorKind, App, AppSettings, Arg};
use clap::{arg, error::ErrorKind, App, Arg};
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;
@ -322,7 +322,7 @@ fn invalid_utf8_option_long_equals() {
#[test]
fn refuse_invalid_utf8_subcommand_with_allow_external_subcommands() {
let m = App::new("bad_utf8")
.setting(AppSettings::AllowExternalSubcommands)
.allow_external_subcommands(true)
.try_get_matches_from(vec![
OsString::from(""),
OsString::from_vec(vec![0xe9]),
@ -335,8 +335,8 @@ fn refuse_invalid_utf8_subcommand_with_allow_external_subcommands() {
#[test]
fn refuse_invalid_utf8_subcommand_when_args_are_allowed_with_allow_external_subcommands() {
let m = App::new("bad_utf8")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.try_get_matches_from(vec![
OsString::from(""),
OsString::from_vec(vec![0xe9]),
@ -349,7 +349,7 @@ fn refuse_invalid_utf8_subcommand_when_args_are_allowed_with_allow_external_subc
#[test]
fn refuse_invalid_utf8_subcommand_args_with_allow_external_subcommands() {
let m = App::new("bad_utf8")
.setting(AppSettings::AllowExternalSubcommands)
.allow_external_subcommands(true)
.try_get_matches_from(vec![
OsString::from(""),
OsString::from("subcommand"),
@ -364,8 +364,8 @@ fn refuse_invalid_utf8_subcommand_args_with_allow_external_subcommands() {
#[test]
fn allow_invalid_utf8_subcommand_args_with_allow_external_subcommands() {
let m = App::new("bad_utf8")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands)
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true)
.try_get_matches_from(vec![
OsString::from(""),
OsString::from("subcommand"),
@ -445,7 +445,7 @@ fn ignore_invalid_utf8_with_defaults() {
#[test]
fn allow_validated_utf8_external_subcommand_values_of() {
let a = App::new("test").setting(AppSettings::AllowExternalSubcommands);
let a = App::new("test").allow_external_subcommands(true);
let m = a.try_get_matches_from(vec!["test", "cmd", "arg"]).unwrap();
let (_ext, args) = m.subcommand().unwrap();
let _ = args.values_of("");
@ -454,7 +454,7 @@ fn allow_validated_utf8_external_subcommand_values_of() {
#[test]
#[should_panic = "Must use `Arg::allow_invalid_utf8` with `_os` lookups at ``"]
fn panic_validated_utf8_external_subcommand_values_of_os() {
let a = App::new("test").setting(AppSettings::AllowExternalSubcommands);
let a = App::new("test").allow_external_subcommands(true);
let m = a.try_get_matches_from(vec!["test", "cmd", "arg"]).unwrap();
let (_ext, args) = m.subcommand().unwrap();
let _ = args.values_of_os("");
@ -463,8 +463,8 @@ fn panic_validated_utf8_external_subcommand_values_of_os() {
#[test]
fn allow_invalid_utf8_external_subcommand_values_of_os() {
let a = App::new("test")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands);
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true);
let m = a.try_get_matches_from(vec!["test", "cmd", "arg"]).unwrap();
let (_ext, args) = m.subcommand().unwrap();
let _ = args.values_of_os("");
@ -474,8 +474,8 @@ fn allow_invalid_utf8_external_subcommand_values_of_os() {
#[should_panic = "Must use `_os` lookups with `Arg::allow_invalid_utf8` at ``"]
fn panic_invalid_utf8_external_subcommand_values_of() {
let a = App::new("test")
.setting(AppSettings::AllowExternalSubcommands)
.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands);
.allow_external_subcommands(true)
.allow_invalid_utf8_for_external_subcommands(true);
let m = a.try_get_matches_from(vec!["test", "cmd", "arg"]).unwrap();
let (_ext, args) = m.subcommand().unwrap();
let _ = args.values_of("");

View file

@ -158,7 +158,7 @@ OPTIONS:
fn version_about_multi_subcmd() {
let app = with_subcommand()
.mut_arg("version", |a| a.help("Print custom version about text"))
.global_setting(AppSettings::PropagateVersion);
.propagate_version(true);
assert!(utils::compare_output(
app,
@ -190,7 +190,7 @@ fn no_propagation_by_default_short() {
#[test]
fn propagate_version_long() {
let res = with_subcommand()
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.try_get_matches_from("foo bar --version".split(' '));
assert!(res.is_err());
@ -201,7 +201,7 @@ fn propagate_version_long() {
#[test]
fn propagate_version_short() {
let res = with_subcommand()
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.try_get_matches_from("foo bar -V".split(' '));
assert!(res.is_err());
@ -234,7 +234,7 @@ fn mut_arg_version_no_auto_version() {
#[should_panic = "No version information via App::version or App::long_version to propagate"]
fn propagate_version_no_version_info() {
let _res = common()
.setting(AppSettings::PropagateVersion)
.propagate_version(true)
.subcommand(App::new("bar"))
.try_get_matches_from("foo".split(' '));
}

View file

@ -194,7 +194,7 @@ fn flatten_field_with_help_heading() {
#[test]
fn derive_generated_error_has_full_context() {
#[derive(Debug, Parser)]
#[clap(setting(AppSettings::SubcommandsNegateReqs))]
#[clap(subcommand_negates_reqs = true)]
struct Opts {
#[clap(long)]
req_str: String,

View file

@ -2,7 +2,7 @@
use crate::utils;
use clap::{AppSettings, ArgGroup, Args, Parser, Subcommand};
use clap::{ArgGroup, Args, Parser, Subcommand};
#[test]
fn issue_151() {
@ -31,7 +31,7 @@ fn issue_151() {
#[test]
fn issue_289() {
#[derive(Parser)]
#[clap(setting = AppSettings::InferSubcommands)]
#[clap(infer_subcommands = true)]
enum Args {
SomeCommand {
#[clap(subcommand)]
@ -41,7 +41,7 @@ fn issue_289() {
}
#[derive(Subcommand)]
#[clap(setting = AppSettings::InferSubcommands)]
#[clap(infer_subcommands = true)]
enum SubSubCommand {
TestCommand,
}

View file

@ -12,14 +12,14 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.
use clap::{AppSettings, ErrorKind, Parser};
use clap::{ErrorKind, Parser};
use std::num::ParseIntError;
pub const DISPLAY_ORDER: usize = 2;
// Check if the global settings compile
#[derive(Parser, Debug, PartialEq, Eq)]
#[clap(global_setting = AppSettings::AllowHyphenValues)]
#[clap(allow_hyphen_values = true)]
struct Opt {
#[clap(
long = "x",

View file

@ -113,7 +113,7 @@ fn option_type_is_optional() {
#[test]
fn required_with_option_type() {
#[derive(Debug, PartialEq, Eq, Parser)]
#[clap(setting(clap::AppSettings::SubcommandsNegateReqs))]
#[clap(subcommand_negates_reqs = true)]
struct Opt {
#[clap(required = true)]
req_str: Option<String>,