diff --git a/benches/03_complex.rs b/benches/03_complex.rs index 377d60ccc21..0e08a225d24 100644 --- a/benches/03_complex.rs +++ b/benches/03_complex.rs @@ -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", diff --git a/benches/06_rustup.rs b/benches/06_rustup.rs index 0f23f16d271..dba5be60f3f 100644 --- a/benches/06_rustup.rs +++ b/benches/06_rustup.rs @@ -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")) diff --git a/clap_complete/examples/value_hints.rs b/clap_complete/examples/value_hints.rs index 074f996f337..5281f78b8bd 100644 --- a/clap_complete/examples/value_hints.rs +++ b/clap_complete/examples/value_hints.rs @@ -12,14 +12,14 @@ //! . ./value_hints.fish //! ./target/debug/examples/value_hints -- //! ``` -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") diff --git a/clap_complete/examples/value_hints_derive.rs b/clap_complete/examples/value_hints_derive.rs index 7644bb489e3..2cbcaadd1e6 100644 --- a/clap_complete/examples/value_hints_derive.rs +++ b/clap_complete/examples/value_hints_derive.rs @@ -12,7 +12,7 @@ //! . ./value_hints_derive.fish //! ./target/debug/examples/value_hints_derive -- //! ``` -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 diff --git a/clap_complete/tests/completions/bash.rs b/clap_complete/tests/completions/bash.rs index 84db7bf643b..eff83f480df 100644 --- a/clap_complete/tests/completions/bash.rs +++ b/clap_complete/tests/completions/bash.rs @@ -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") diff --git a/clap_complete/tests/completions/elvish.rs b/clap_complete/tests/completions/elvish.rs index 35295bd786b..0926a1606f8 100644 --- a/clap_complete/tests/completions/elvish.rs +++ b/clap_complete/tests/completions/elvish.rs @@ -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") diff --git a/clap_complete/tests/completions/fish.rs b/clap_complete/tests/completions/fish.rs index 1a47d182c75..0da349c2b8d 100644 --- a/clap_complete/tests/completions/fish.rs +++ b/clap_complete/tests/completions/fish.rs @@ -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") diff --git a/clap_complete/tests/completions/mod.rs b/clap_complete/tests/completions/mod.rs index 7eaadd24662..f3b947a8938 100644 --- a/clap_complete/tests/completions/mod.rs +++ b/clap_complete/tests/completions/mod.rs @@ -1,4 +1,4 @@ -use clap::{App, AppSettings, Arg, ValueHint}; +use clap::{App, Arg, ValueHint}; use clap_complete::{generate, shells::*, Generator}; use std::fmt; diff --git a/clap_complete/tests/completions/powershell.rs b/clap_complete/tests/completions/powershell.rs index 2bb4d815401..914ba89def3 100644 --- a/clap_complete/tests/completions/powershell.rs +++ b/clap_complete/tests/completions/powershell.rs @@ -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") diff --git a/clap_complete/tests/completions/zsh.rs b/clap_complete/tests/completions/zsh.rs index 52eda31ec6a..73dbc43bcc8 100644 --- a/clap_complete/tests/completions/zsh.rs +++ b/clap_complete/tests/completions/zsh.rs @@ -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") diff --git a/clap_complete/tests/value_hints.rs b/clap_complete/tests/value_hints.rs index 7cb38add736..60b586b15e8 100644 --- a/clap_complete/tests/value_hints.rs +++ b/clap_complete/tests/value_hints.rs @@ -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") diff --git a/clap_complete_fig/tests/completions/fig.rs b/clap_complete_fig/tests/completions/fig.rs index 24456362e15..4e7860ea425 100644 --- a/clap_complete_fig/tests/completions/fig.rs +++ b/clap_complete_fig/tests/completions/fig.rs @@ -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") diff --git a/clap_complete_fig/tests/completions/mod.rs b/clap_complete_fig/tests/completions/mod.rs index fc7f212f4d0..f2923d8c2ff 100644 --- a/clap_complete_fig/tests/completions/mod.rs +++ b/clap_complete_fig/tests/completions/mod.rs @@ -1,4 +1,4 @@ -use clap::{App, AppSettings, Arg, ValueHint}; +use clap::{App, Arg, ValueHint}; use clap_complete::{generate, Generator}; use std::fmt; diff --git a/clap_complete_fig/tests/value_hints.rs b/clap_complete_fig/tests/value_hints.rs index df3c6c57c57..15fa4e235aa 100644 --- a/clap_complete_fig/tests/value_hints.rs +++ b/clap_complete_fig/tests/value_hints.rs @@ -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") diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs index 8f1b4510ce3..1e53375fb9a 100644 --- a/clap_derive/src/derives/subcommand.rs +++ b/clap_derive/src/derives/subcommand.rs @@ -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); } } } diff --git a/clap_mangen/src/lib.rs b/clap_mangen/src/lib.rs index 8164ce5f5c9..60f6cd91976 100644 --- a/clap_mangen/src/lib.rs +++ b/clap_mangen/src/lib.rs @@ -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()) } diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index 14980fcad5c..df753ae302c 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -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) { diff --git a/examples/cargo-example.rs b/examples/cargo-example.rs index a3f33ee7a54..51356dc40a5 100644 --- a/examples/cargo-example.rs +++ b/examples/cargo-example.rs @@ -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" ) diff --git a/examples/git-derive.rs b/examples/git-derive.rs index 4f0cf80e07e..28cc593ef1d 100644 --- a/examples/git-derive.rs +++ b/examples/git-derive.rs @@ -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))] diff --git a/examples/git.rs b/examples/git.rs index 1a55fae2088..8d7108cad67 100644 --- a/examples/git.rs +++ b/examples/git.rs @@ -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!( "The remote to clone")) - .setting(AppSettings::ArgRequiredElseHelp), + .arg_required_else_help(true), ) .subcommand( App::new("push") .about("pushes things") .arg(arg!( "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!( ... "Stuff to add").allow_invalid_utf8(true)), ) .get_matches(); diff --git a/examples/multicall-busybox.rs b/examples/multicall-busybox.rs index bb7db04347b..8d49fe7269c 100644 --- a/examples/multicall-busybox.rs +++ b/examples/multicall-busybox.rs @@ -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( diff --git a/examples/multicall-hostname.rs b/examples/multicall-hostname.rs index bb1223dcad1..eb19cd47136 100644 --- a/examples/multicall-hostname.rs +++ b/examples/multicall-hostname.rs @@ -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"), diff --git a/examples/tutorial_builder/02_app_settings.rs b/examples/tutorial_builder/02_app_settings.rs index 6cfca11f6f8..213b6e58bc9 100644 --- a/examples/tutorial_builder/02_app_settings.rs +++ b/examples/tutorial_builder/02_app_settings.rs @@ -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 )) .arg(arg!(--one )) .get_matches(); diff --git a/examples/tutorial_builder/03_04_subcommands.rs b/examples/tutorial_builder/03_04_subcommands.rs index 75db59df6de..ed1c952243b 100644 --- a/examples/tutorial_builder/03_04_subcommands.rs +++ b/examples/tutorial_builder/03_04_subcommands.rs @@ -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( diff --git a/examples/tutorial_builder/README.md b/examples/tutorial_builder/README.md index a081d7c0608..0679f6ff946 100644 --- a/examples/tutorial_builder/README.md +++ b/examples/tutorial_builder/README.md @@ -326,7 +326,7 @@ SUBCOMMANDS: ``` -Because we set `AppSettings::PropagateVersion`: +Because we set `App::propagate_version`: ```console $ 03_04_subcommands --version clap [..] diff --git a/examples/tutorial_derive/02_app_settings.rs b/examples/tutorial_derive/02_app_settings.rs index 6c9fbd73cb9..bccd353f602 100644 --- a/examples/tutorial_derive/02_app_settings.rs +++ b/examples/tutorial_derive/02_app_settings.rs @@ -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, diff --git a/examples/tutorial_derive/03_04_subcommands.rs b/examples/tutorial_derive/03_04_subcommands.rs index 8e272dcdd0a..01efc3be752 100644 --- a/examples/tutorial_derive/03_04_subcommands.rs +++ b/examples/tutorial_derive/03_04_subcommands.rs @@ -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)] diff --git a/examples/tutorial_derive/README.md b/examples/tutorial_derive/README.md index 45f582d171d..9f97bb4999b 100644 --- a/examples/tutorial_derive/README.md +++ b/examples/tutorial_derive/README.md @@ -328,7 +328,7 @@ SUBCOMMANDS: ``` -Because we set `AppSettings::PropagateVersion`: +Because we set `App::propagate_version`: ```console $ 03_04_subcommands_derive --version clap [..] diff --git a/src/build/app.rs b/src/build/app.rs index b709e4aef3c..09fc0da3485 100644 --- a/src/build/app.rs +++ b/src/build/app.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + // Std use std::{ collections::HashMap, @@ -16,6 +18,7 @@ use yaml_rust::Yaml; // Internal use crate::build::app_settings::{AppFlags, AppSettings}; +use crate::build::arg_settings::ArgSettings; use crate::build::{arg::ArgProvider, Arg, ArgGroup, ArgPredicate}; use crate::error::ErrorKind; use crate::error::Result as ClapResult; @@ -840,6 +843,114 @@ impl<'help> App<'help> { /// These settings will apply to the top-level command and all subcommands, by default. Some /// settings can be overridden in subcommands. impl<'help> App<'help> { + /// 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") + /// .no_binary_name(true) + /// .arg(arg!( ... "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() + #[inline] + pub fn no_binary_name(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::NoBinaryName) + } else { + self.unset_global_setting(AppSettings::NoBinaryName) + } + } + + /// 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! + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, arg}; + /// let app = App::new("app") + /// .ignore_errors(true) + /// .arg(arg!(-c --config "Sets a custom config file").required(false)) + /// .arg(arg!(-x --stuff "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); + /// ``` + #[inline] + pub fn ignore_errors(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::IgnoreErrors) + } else { + self.unset_global_setting(AppSettings::IgnoreErrors) + } + } + + /// Specifies that all arguments override themselves. + /// + /// This is the equivalent to saying the `foo` arg using [`Arg::overrides_with("foo")`] for all + /// defined arguments. + /// + /// **NOTE:** This will not be applied when [`Arg::multiple_occurrences(true)`]. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// [`Arg::overrides_with("foo")`]: crate::Arg::overrides_with() + #[inline] + pub fn args_override_self(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::AllArgsOverrideSelf) + } else { + self.unset_global_setting(AppSettings::AllArgsOverrideSelf) + } + } + + /// Disables the automatic delimiting of values after `--` or when [`App::trailing_var_arg`] + /// 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. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// App::new("myprog") + /// .dont_delimit_trailing_values(true) + /// .get_matches(); + /// ``` + /// + /// [`Arg::use_value_delimiter(false)`]: crate::Arg::use_value_delimiter() + #[inline] + pub fn dont_delimit_trailing_values(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DontDelimitTrailingValues) + } else { + self.unset_global_setting(AppSettings::DontDelimitTrailingValues) + } + } + /// Sets when to color output. /// /// **NOTE:** This choice is propagated to all child subcommands. @@ -918,6 +1029,299 @@ impl<'help> App<'help> { self.max_w = Some(w); self } + + /// Disables `-V` and `--version` flag. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, ErrorKind}; + /// let res = App::new("myprog") + /// .disable_version_flag(true) + /// .try_get_matches_from(vec![ + /// "myprog", "-V" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); + /// ``` + #[inline] + pub fn disable_version_flag(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DisableVersionFlag) + } else { + self.unset_global_setting(AppSettings::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! + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// App::new("myprog") + /// .version("v1.1") + /// .propagate_version(true) + /// .subcommand(App::new("test")) + /// .get_matches(); + /// // running `$ myprog test --version` will display + /// // "myprog-test v1.1" + /// ``` + /// + /// [`subcommands`]: crate::App::subcommand() + #[inline] + pub fn propagate_version(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::PropagateVersion) + } else { + self.unset_global_setting(AppSettings::PropagateVersion) + } + } + + /// Places the help string for all arguments and subcommands on the line after them. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// App::new("myprog") + /// .next_line_help(true) + /// .get_matches(); + /// ``` + #[inline] + pub fn next_line_help(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::NextLineHelp) + } else { + self.unset_global_setting(AppSettings::NextLineHelp) + } + } + + /// Disables `-h` and `--help` flag. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, ErrorKind}; + /// let res = App::new("myprog") + /// .disable_help_flag(true) + /// .try_get_matches_from(vec![ + /// "myprog", "-h" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); + /// ``` + #[inline] + pub fn disable_help_flag(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DisableHelpFlag) + } else { + self.unset_global_setting(AppSettings::DisableHelpFlag) + } + } + + /// Disables the `help` [`subcommand`]. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, ErrorKind}; + /// let res = App::new("myprog") + /// .disable_help_subcommand(true) + /// // 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() + #[inline] + pub fn disable_help_subcommand(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DisableHelpSubcommand) + } else { + self.unset_global_setting(AppSettings::DisableHelpSubcommand) + } + } + + /// Disables colorized help messages. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::App; + /// App::new("myprog") + /// .disable_colored_help(true) + /// .get_matches(); + /// ``` + #[inline] + pub fn disable_colored_help(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DisableColoredHelp) + } else { + self.unset_global_setting(AppSettings::DisableColoredHelp) + } + } + + /// Panic if help descriptions are omitted. + /// + /// **NOTE:** When deriving [`Parser`][crate::Parser], you could instead check this at + /// compile-time with `#![deny(missing_docs)]` + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, Arg}; + /// App::new("myprog") + /// .help_expected(true) + /// .arg( + /// Arg::new("foo").help("It does foo stuff") + /// // As required via `help_expected`, a help message was supplied + /// ) + /// # .get_matches(); + /// ``` + /// + /// # Panics + /// + /// ```rust,no_run + /// # use clap::{App, Arg}; + /// App::new("myapp") + /// .help_expected(true) + /// .arg( + /// Arg::new("foo") + /// // Someone forgot to put .about("...") here + /// // Since the setting `help_expected` is activated, this will lead to + /// // a panic (if you are in debug mode) + /// ) + /// # .get_matches(); + ///``` + #[inline] + pub fn help_expected(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::HelpExpected) + } else { + self.unset_global_setting(AppSettings::HelpExpected) + } + } + + /// Disables the automatic collapsing of positional args into `[ARGS]` inside the usage string. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// App::new("myprog") + /// .dont_collapse_args_in_usage(true) + /// .get_matches(); + /// ``` + #[inline] + pub fn dont_collapse_args_in_usage(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::DontCollapseArgsInUsage) + } else { + self.unset_global_setting(AppSettings::DontCollapseArgsInUsage) + } + } + + /// 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]. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + #[inline] + pub fn hide_possible_values(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::HidePossibleValues) + } else { + self.unset_global_setting(AppSettings::HidePossibleValues) + } + } + + /// 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` + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// [aliases]: crate::App::aliases() + #[inline] + pub fn infer_long_args(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::InferLongArgs) + } else { + self.unset_global_setting(AppSettings::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. + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// # Examples + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// let m = App::new("prog") + /// .infer_subcommands(true) + /// .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() + #[inline] + pub fn infer_subcommands(self, yes: bool) -> Self { + if yes { + self.global_setting(AppSettings::InferSubcommands) + } else { + self.unset_global_setting(AppSettings::InferSubcommands) + } + } } /// Command-specific Settings @@ -1538,49 +1942,279 @@ impl<'help> App<'help> { self.replacers.insert(name, target); self } -} -/// Subcommand-specific Settings -impl<'help> App<'help> { - /// Sets the short version of the subcommand flag without the preceding `-`. + /// Exit gracefully if no arguments are present (e.g. `$ myprog`). /// - /// Allows the subcommand to be used as if it were an [`Arg::short`]. + /// **NOTE:** [`subcommands`] count as arguments /// /// # Examples /// + /// ```rust + /// # use clap::{App}; + /// App::new("myprog") + /// .arg_required_else_help(true); /// ``` - /// # use clap::{App, Arg}; - /// let matches = App::new("pacman") - /// .subcommand( - /// App::new("sync").short_flag('S').arg( - /// Arg::new("search") - /// .short('s') - /// .long("search") - /// .help("search remote repositories for matching strings"), - /// ), - /// ) - /// .get_matches_from(vec!["pacman", "-Ss"]); /// - /// assert_eq!(matches.subcommand_name().unwrap(), "sync"); - /// let sync_matches = matches.subcommand_matches("sync").unwrap(); - /// assert!(sync_matches.is_present("search")); - /// ``` - /// [`Arg::short`]: Arg::short() - #[must_use] - pub fn short_flag(mut self, short: char) -> Self { - self.short_flag = Some(short); - self + /// [`subcommands`]: crate::App::subcommand() + /// [`Arg::default_value`]: crate::Arg::default_value() + #[inline] + pub fn arg_required_else_help(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::ArgRequiredElseHelp) + } else { + self.unset_setting(AppSettings::ArgRequiredElseHelp) + } } - /// Sets the long version of the subcommand flag without the preceding `--`. + /// Specifies that leading hyphens are allowed in all argument *values* (e.g. `-10`). /// - /// Allows the subcommand to be used as if it were an [`Arg::long`]. + /// Otherwise they will be parsed as another flag or option. See also + /// [`App::allow_negative_numbers`]. /// - /// **NOTE:** Any leading `-` characters will be stripped. + /// **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 /// - /// To set `long_flag` use a word containing valid UTF-8 codepoints. If you supply a double leading + /// ```rust + /// # use clap::{Arg, App}; + /// // Imagine you needed to represent negative numbers as well, such as -10 + /// let m = App::new("nums") + /// .allow_hyphen_values(true) + /// .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() + #[inline] + pub fn allow_hyphen_values(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::AllowHyphenValues) + } else { + self.unset_setting(AppSettings::AllowHyphenValues) + } + } + + /// Allows negative numbers to pass as values. + /// + /// This is similar to [`App::allow_hyphen_values`] except that it only allows numbers, + /// all other undefined leading hyphens will fail to parse. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, Arg}; + /// let res = App::new("myprog") + /// .allow_negative_numbers(true) + /// .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"); + /// ``` + #[inline] + pub fn allow_negative_numbers(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::AllowNegativeNumbers) + } else { + self.unset_setting(AppSettings::AllowNegativeNumbers) + } + } + + /// 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}; + /// let m = App::new("myprog") + /// .trailing_var_arg(true) + /// .arg(arg!( ... "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() + pub fn trailing_var_arg(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::TrailingVarArg) + } else { + self.unset_setting(AppSettings::TrailingVarArg) + } + } + + /// 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] ` where one + /// of the two following usages is allowed: + /// + /// * `$ prog [optional] ` + /// * `$ prog ` + /// + /// 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}; + /// // Assume there is an external subcommand named "subcmd" + /// let m = App::new("myprog") + /// .allow_missing_positional(true) + /// .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}; + /// // Assume there is an external subcommand named "subcmd" + /// let m = App::new("myprog") + /// .allow_missing_positional(true) + /// .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}; + /// // Assume there is an external subcommand named "subcmd" + /// let m = App::new("myprog") + /// .allow_missing_positional(true) + /// .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::>(), &["baz1", "baz2", "baz3"]); + /// ``` + /// + /// Now nofice if we don't specify `foo` or `baz` but use the `--` operator. + /// + /// ```rust + /// # use clap::{App, Arg}; + /// // Assume there is an external subcommand named "subcmd" + /// let m = App::new("myprog") + /// .allow_missing_positional(true) + /// .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::>(), &["baz1", "baz2", "baz3"]); + /// ``` + /// + /// [required]: crate::Arg::required() + #[inline] + pub fn allow_missing_positional(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::AllowMissingPositional) + } else { + self.unset_setting(AppSettings::AllowMissingPositional) + } + } +} + +/// Subcommand-specific Settings +impl<'help> App<'help> { + /// Sets the short version of the subcommand flag without the preceding `-`. + /// + /// Allows the subcommand to be used as if it were an [`Arg::short`]. + /// + /// # Examples + /// + /// ``` + /// # use clap::{App, Arg}; + /// let matches = App::new("pacman") + /// .subcommand( + /// App::new("sync").short_flag('S').arg( + /// Arg::new("search") + /// .short('s') + /// .long("search") + /// .help("search remote repositories for matching strings"), + /// ), + /// ) + /// .get_matches_from(vec!["pacman", "-Ss"]); + /// + /// assert_eq!(matches.subcommand_name().unwrap(), "sync"); + /// let sync_matches = matches.subcommand_matches("sync").unwrap(); + /// assert!(sync_matches.is_present("search")); + /// ``` + /// [`Arg::short`]: Arg::short() + #[must_use] + pub fn short_flag(mut self, short: char) -> Self { + self.short_flag = Some(short); + self + } + + /// Sets the long version of the subcommand flag without the preceding `--`. + /// + /// Allows the subcommand to be used as if it were an [`Arg::long`]. + /// + /// **NOTE:** Any leading `-` characters will be stripped. + /// + /// # Examples + /// + /// To set `long_flag` use a word containing valid UTF-8 codepoints. If you supply a double leading /// `--` such as `--sync` they will be stripped. Hyphens in the middle of the word; however, /// will *not* be stripped (i.e. `sync-file` is allowed). /// @@ -1996,6 +2630,392 @@ impl<'help> App<'help> { self } + /// Specifies that this [`subcommand`] should be hidden from help messages + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, Arg, AppSettings, }; + /// App::new("myprog") + /// .subcommand( + /// App::new("test").hide(true) + /// ) + /// # ; + /// ``` + /// + /// [`subcommand`]: crate::App::subcommand() + #[inline] + pub fn hide(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::Hidden) + } else { + self.unset_setting(AppSettings::Hidden) + } + } + + /// If no [`subcommand`] is present at runtime, error and exit gracefully. + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, AppSettings, ErrorKind}; + /// let err = App::new("myprog") + /// .subcommand_required(true) + /// .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() + pub fn subcommand_required(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::SubcommandRequired) + } else { + self.unset_setting(AppSettings::SubcommandRequired) + } + } + + /// 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") + /// .allow_external_subcommands(true) + /// .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 + pub fn allow_external_subcommands(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::AllowExternalSubcommands) + } else { + self.unset_setting(AppSettings::AllowExternalSubcommands) + } + } + + /// 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 [`App::allow_external_subcommands`] + /// + /// # 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") + /// .allow_invalid_utf8_for_external_subcommands(true) + /// .allow_external_subcommands(true) + /// .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() + pub fn allow_invalid_utf8_for_external_subcommands(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands) + } else { + self.unset_setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands) + } + } + + /// Specifies that use of an argument prevents the use of [`subcommands`]. + /// + /// By default `clap` allows arguments between subcommands such + /// as ` [cmd_args] [subcmd_args] [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: + /// + /// * ` [subsubcmd_args]` + /// * ` [subcmd_args]` + /// * ` [cmd_args]` + /// + /// # Examples + /// + /// ```rust + /// # use clap::{App, AppSettings}; + /// App::new("myprog") + /// .args_conflicts_with_subcommands(true); + /// ``` + /// + /// [`subcommands`]: crate::App::subcommand() + pub fn args_conflicts_with_subcommands(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::ArgsNegateSubcommands) + } else { + self.unset_setting(AppSettings::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::>(), + /// &["1", "2", "3", "sub"] + /// ); + /// assert!(matches.subcommand_matches("sub").is_none()); + /// + /// let matches = app + /// .subcommand_precedence_over_arg(true) + /// .try_get_matches_from(&["app", "--arg", "1", "2", "3", "sub"]) + /// .unwrap(); + /// assert_eq!( + /// matches.values_of("arg").unwrap().collect::>(), + /// &["1", "2", "3"] + /// ); + /// assert!(matches.subcommand_matches("sub").is_some()); + /// ``` + pub fn subcommand_precedence_over_arg(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::SubcommandPrecedenceOverArg) + } else { + self.unset_setting(AppSettings::SubcommandPrecedenceOverArg) + } + } + + /// 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") + /// .subcommand_negates_reqs(true) + /// .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") + /// .subcommand_negates_reqs(true) + /// .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() + pub fn subcommand_negates_reqs(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::SubcommandsNegateReqs) + } else { + self.unset_setting(AppSettings::SubcommandsNegateReqs) + } + } + + /// 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") + /// .multicall(true) + /// .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") + /// .multicall(true) + /// .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 + #[inline] + #[cfg(feature = "unstable-multicall")] + pub fn multicall(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::Multicall) + } else { + self.unset_setting(AppSettings::Multicall) + } + } + /// Sets the value name used for subcommands when printing usage and help. /// /// By default, this is "SUBCOMMAND". @@ -2452,6 +3472,139 @@ impl<'help> App<'help> { } vec } + + /// Report whether [`App::no_binary_name`] is set + #[allow(unused)] + pub(crate) fn is_no_binary_name_set(&self) -> bool { + self.is_set(AppSettings::NoBinaryName) + } + + /// Report whether [`App::ignore_errors`] is set + pub(crate) fn is_ignore_errors_set(&self) -> bool { + self.is_set(AppSettings::IgnoreErrors) + } + + /// Report whether [`App::dont_delimit_trailing_values`] is set + pub fn is_dont_delimit_trailing_values_set(&self) -> bool { + self.is_set(AppSettings::DontDelimitTrailingValues) + } + + /// Report whether [`App::disable_version_flag`] is set + pub fn is_disable_version_flag_set(&self) -> bool { + self.is_set(AppSettings::DisableVersionFlag) + } + + /// Report whether [`App::propagate_version`] is set + pub fn is_propagate_version_set(&self) -> bool { + self.is_set(AppSettings::PropagateVersion) + } + + /// Report whether [`App::next_line_help`] is set + pub fn is_next_line_help_set(&self) -> bool { + self.is_set(AppSettings::NextLineHelp) + } + + /// Report whether [`App::disable_help_flag`] is set + pub fn is_disable_help_flag_set(&self) -> bool { + self.is_set(AppSettings::DisableHelpFlag) + } + + /// Report whether [`App::disable_help_subcommand`] is set + pub fn is_disable_help_subcommand_set(&self) -> bool { + self.is_set(AppSettings::DisableHelpSubcommand) + } + + /// Report whether [`App::disable_colored_help`] is set + pub fn is_disable_colored_help_set(&self) -> bool { + self.is_set(AppSettings::DisableColoredHelp) + } + + /// Report whether [`App::help_expected`] is set + #[cfg(debug_assertions)] + pub(crate) fn is_help_expected_set(&self) -> bool { + self.is_set(AppSettings::HelpExpected) + } + + /// Report whether [`App::dont_collapse_args_in_usage`] is set + pub fn is_dont_collapse_args_in_usage_set(&self) -> bool { + self.is_set(AppSettings::DontCollapseArgsInUsage) + } + + /// Report whether [`App::infer_long_args`] is set + pub(crate) fn is_infer_long_args_set(&self) -> bool { + self.is_set(AppSettings::InferLongArgs) + } + + /// Report whether [`App::infer_subcommands`] is set + pub(crate) fn is_infer_subcommands_set(&self) -> bool { + self.is_set(AppSettings::InferSubcommands) + } + + /// Report whether [`App::arg_required_else_help`] is set + pub fn is_arg_required_else_help_set(&self) -> bool { + self.is_set(AppSettings::ArgRequiredElseHelp) + } + + /// Report whether [`App::allow_hyphen_values`] is set + pub(crate) fn is_allow_hyphen_values_set(&self) -> bool { + self.is_set(AppSettings::AllowHyphenValues) + } + + /// Report whether [`App::allow_negative_numbers`] is set + pub fn is_allow_negative_numbers_set(&self) -> bool { + self.is_set(AppSettings::AllowNegativeNumbers) + } + + /// Report whether [`App::trailing_var_arg`] is set + pub fn is_trailing_var_arg_set(&self) -> bool { + self.is_set(AppSettings::TrailingVarArg) + } + + /// Report whether [`App::allow_missing_positional`] is set + pub fn is_allow_missing_positional_set(&self) -> bool { + self.is_set(AppSettings::AllowMissingPositional) + } + + /// Report whether [`App::hide`] is set + pub fn is_hide_set(&self) -> bool { + self.is_set(AppSettings::Hidden) + } + + /// Report whether [`App::subcommand_required`] is set + pub fn is_subcommand_required_set(&self) -> bool { + self.is_set(AppSettings::SubcommandRequired) + } + + /// Report whether [`App::allow_external_subcommands`] is set + pub fn is_allow_external_subcommands_set(&self) -> bool { + self.is_set(AppSettings::AllowExternalSubcommands) + } + + /// Report whether [`App::allow_invalid_utf8_for_external_subcommands`] is set + pub fn is_allow_invalid_utf8_for_external_subcommands_set(&self) -> bool { + self.is_set(AppSettings::AllowInvalidUtf8ForExternalSubcommands) + } + + /// Report whether [`App::args_conflicts_with_subcommands`] is set + pub fn is_args_conflicts_with_subcommands_set(&self) -> bool { + self.is_set(AppSettings::ArgsNegateSubcommands) + } + + /// Report whether [`App::subcommand_precedence_over_arg`] is set + pub fn is_subcommand_precedence_over_arg_set(&self) -> bool { + self.is_set(AppSettings::SubcommandPrecedenceOverArg) + } + + /// Report whether [`App::subcommand_negates_reqs`] is set + pub fn is_subcommand_negates_reqs_set(&self) -> bool { + self.is_set(AppSettings::SubcommandsNegateReqs) + } + + /// Report whether [`App::multicall`] is set + #[cfg(feature = "unstable-multicall")] + pub fn is_multicall_set(&self) -> bool { + self.is_set(AppSettings::Multicall) + } } /// Deprecated @@ -2767,6 +3920,7 @@ impl<'help> App<'help> { let mut pos_counter = 1; let self_override = self.is_set(AppSettings::AllArgsOverrideSelf); + let hide_pv = self.is_set(AppSettings::HidePossibleValues); for a in self.args.args_mut() { // Fill in the groups for g in &a.groups { @@ -2785,6 +3939,9 @@ impl<'help> App<'help> { // in the usage string don't get confused or left out. self.settings.set(AppSettings::DontCollapseArgsInUsage); } + if hide_pv && a.is_takes_value_set() { + a.settings.set(ArgSettings::HidePossibleValues); + } if self_override { let self_id = a.id.clone(); a.overrides.push(self_id); diff --git a/src/build/app_settings.rs b/src/build/app_settings.rs index ba020046667..fd92f328f08 100644 --- a/src/build/app_settings.rs +++ b/src/build/app_settings.rs @@ -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 "Sets a custom config file").required(false)) - /// .arg(arg!(-x --stuff "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] ` where one - /// of the two following usages is allowed: - /// - /// * `$ prog [optional] ` - /// * `$ prog ` - /// - /// 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::>(), &["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::>(), &["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!( ... "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_args] [subcmd_args] [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: - /// - /// * ` [subsubcmd_args]` - /// * ` [subcmd_args]` - /// * ` [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::>(), - /// &["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::>(), - /// &["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!( ... "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 diff --git a/src/build/app_tests.rs b/src/build/app_tests.rs index 579243baadb..5349d9f7d28 100644 --- a/src/build/app_tests.rs +++ b/src/build/app_tests.rs @@ -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()); } diff --git a/src/build/arg.rs b/src/build/arg.rs index efa2082b00f..499eade3f2a 100644 --- a/src/build/arg.rs +++ b/src/build/arg.rs @@ -472,7 +472,7 @@ impl<'help> Arg<'help> { /// **NOTE:** This will change the usage string to look like `$ prog [OPTIONS] [-- ]` 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 diff --git a/src/build/debug_asserts.rs b/src/build/debug_asserts.rs index 185037caea7..85874b7f7e0 100644 --- a/src/build/debug_asserts.rs +++ b/src/build/debug_asserts.rs @@ -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(slice: &[T]) -> impl Iterator } 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 \ diff --git a/src/output/help.rs b/src/output/help.rs index c651358c266..16439a43417 100644 --- a/src/output/help.rs +++ b/src/output/help.rs @@ -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 { diff --git a/src/output/usage.rs b/src/output/usage.rs index 7720aaaf74b..f8e1650e7e9 100644 --- a/src/output/usage.rs +++ b/src/output/usage.rs @@ -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 { diff --git a/src/parse/arg_matcher.rs b/src/parse/arg_matcher.rs index ab7002c6280..12e76514b6e 100644 --- a/src/parse/arg_matcher.rs +++ b/src/parse/arg_matcher.rs @@ -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() }) } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index df7614c6440..9a637089156 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -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[¤t_positional.id].is_allow_hyphen_values_set() - || (self.is_set(AS::AllowNegativeNumbers) && next.to_str_lossy().parse::().is_ok()) + || (self.app.is_allow_negative_numbers_set() + && next.to_str_lossy().parse::().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::().is_ok() { + if self.app.is_allow_negative_numbers_set() && arg.parse::().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 diff --git a/src/parse/validator.rs b/src/parse/validator.rs index c2694ba4377..6417f910b0e 100644 --- a/src/parse/validator.rs +++ b/src/parse/validator.rs @@ -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)?; diff --git a/tests/builder/app_settings.rs b/tests/builder/app_settings.rs index 1342cdcba14..1502b3eefa8 100644 --- a/tests/builder/app_settings.rs +++ b/tests/builder/app_settings.rs @@ -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 ).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 "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 "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!( "some arg")) .arg(arg!( "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!( "some arg")) .arg(arg!( "some arg")) .subcommand( App::new("sub1") + .args_conflicts_with_subcommands(true) + .subcommand_negates_reqs(true) .arg(arg!( "some")) .arg(arg!( "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!( "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!( "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!( "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" )) .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 "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 "some option").required(false)) .arg( arg!(--other "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 "some option").required(true)) .arg( arg!(--other "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 "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 "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 ... "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 ... "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 "some option").use_value_delimiter(false)) .try_get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]) .unwrap(); diff --git a/tests/builder/flag_subcommands.rs b/tests/builder/flag_subcommands.rs index bd98c462980..9decadfda71 100644 --- a/tests/builder/flag_subcommands.rs +++ b/tests/builder/flag_subcommands.rs @@ -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 // diff --git a/tests/builder/grouped_values.rs b/tests/builder/grouped_values.rs index 5bcfd20e6b5..fb88ac37c65 100644 --- a/tests/builder/grouped_values.rs +++ b/tests/builder/grouped_values.rs @@ -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")); diff --git a/tests/builder/help.rs b/tests/builder/help.rs index c7c6f672234..a09e8152831 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -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 "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 "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 "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 "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( diff --git a/tests/builder/hidden_args.rs b/tests/builder/hidden_args.rs index 44879f5a608..7ae82e2a4d1 100644 --- a/tests/builder/hidden_args.rs +++ b/tests/builder/hidden_args.rs @@ -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, diff --git a/tests/builder/ignore_errors.rs b/tests/builder/ignore_errors.rs index 4d4d07b1bee..f3da817712b 100644 --- a/tests/builder/ignore_errors.rs +++ b/tests/builder/ignore_errors.rs @@ -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( diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index af60de34aab..74f11af491f 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -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(); diff --git a/tests/builder/positionals.rs b/tests/builder/positionals.rs index 08d16406427..485f3e4f1c3 100644 --- a/tests/builder/positionals.rs +++ b/tests/builder/positionals.rs @@ -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") diff --git a/tests/builder/subcommands.rs b/tests/builder/subcommands.rs index 1077f512e55..5672cf03641 100644 --- a/tests/builder/subcommands.rs +++ b/tests/builder/subcommands.rs @@ -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")); diff --git a/tests/builder/utf8.rs b/tests/builder/utf8.rs index a47171f733b..20b95510d83 100644 --- a/tests/builder/utf8.rs +++ b/tests/builder/utf8.rs @@ -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(""); diff --git a/tests/builder/version.rs b/tests/builder/version.rs index 7125a4208c2..06e38c20d21 100644 --- a/tests/builder/version.rs +++ b/tests/builder/version.rs @@ -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(' ')); } diff --git a/tests/derive/help.rs b/tests/derive/help.rs index c471a0eb329..54fca8a07f1 100644 --- a/tests/derive/help.rs +++ b/tests/derive/help.rs @@ -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, diff --git a/tests/derive/issues.rs b/tests/derive/issues.rs index a1813b8c5be..44e900575bd 100644 --- a/tests/derive/issues.rs +++ b/tests/derive/issues.rs @@ -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, } diff --git a/tests/derive/non_literal_attributes.rs b/tests/derive/non_literal_attributes.rs index ff082709048..4fde20572f7 100644 --- a/tests/derive/non_literal_attributes.rs +++ b/tests/derive/non_literal_attributes.rs @@ -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", diff --git a/tests/derive/options.rs b/tests/derive/options.rs index c0ab79e8a16..88507eb113c 100644 --- a/tests/derive/options.rs +++ b/tests/derive/options.rs @@ -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,