From 8e9c4c6c648472849e40851dcd8c2c62745f25c0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 26 Jul 2022 09:34:23 -0500 Subject: [PATCH 1/2] fix: Be explicit on help/version action --- src/builder/command.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/builder/command.rs b/src/builder/command.rs index 3770995b5f4..00bd90405b2 100644 --- a/src/builder/command.rs +++ b/src/builder/command.rs @@ -12,6 +12,7 @@ use std::path::Path; // Internal use crate::builder::app_settings::{AppFlags, AppSettings}; use crate::builder::arg_settings::ArgSettings; +use crate::builder::ArgAction; use crate::builder::{arg::ArgProvider, Arg, ArgGroup, ArgPredicate}; use crate::error::ErrorKind; use crate::error::Result as ClapResult; @@ -134,6 +135,7 @@ impl<'help> Command<'help> { .arg( Arg::new("help") .long("help") + .action(ArgAction::Help) .help("Print help information") .global(true) .generated(), @@ -141,6 +143,7 @@ impl<'help> Command<'help> { .arg( Arg::new("version") .long("version") + .action(ArgAction::Version) .help("Print version information") .global(true) .generated(), From 5f20fe19303ba3676635df5269d5a004d4880cb3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 25 Jul 2022 19:17:01 -0500 Subject: [PATCH 2/2] docs: Shift focus from takes_value to actions --- clap_bench/benches/03_complex.rs | 10 +- clap_bench/benches/04_new_help.rs | 6 +- clap_bench/benches/05_ripgrep.rs | 15 +- clap_bench/benches/06_rustup.rs | 71 ++- clap_complete/examples/completion.rs | 1 - clap_complete/src/generator/mod.rs | 6 +- clap_complete/src/generator/utils.rs | 2 + clap_complete/src/lib.rs | 4 +- clap_complete/tests/common.rs | 39 +- clap_complete_fig/tests/common.rs | 39 +- clap_derive/src/derives/args.rs | 7 - clap_mangen/examples/man.rs | 1 - clap_mangen/tests/common.rs | 50 +- .../tests/snapshots/feature_sample.bash.roff | 2 +- .../snapshots/special_commands.bash.roff | 2 +- .../tests/snapshots/sub_subcommands.bash.roff | 2 +- examples/derive_ref/flatten_hand_args.rs | 14 +- examples/multicall-busybox.rs | 4 +- examples/pacman.rs | 8 +- src/_derive/mod.rs | 16 +- src/bin/stdio-fixture.rs | 1 + src/builder/arg.rs | 540 +++++++++--------- src/builder/arg_group.rs | 90 +-- src/builder/command.rs | 23 +- src/builder/possible_value.rs | 4 +- src/builder/value_parser.rs | 22 +- src/derive.rs | 2 +- src/error/kind.rs | 18 +- src/macros.rs | 44 +- src/parser/matches/arg_matches.rs | 97 ++-- tests/builder/app_settings.rs | 13 +- tests/builder/arg_aliases.rs | 13 +- tests/builder/arg_aliases_short.rs | 11 +- tests/builder/arg_matcher_assertions.rs | 2 +- tests/builder/conflicts.rs | 17 +- tests/builder/default_missing_vals.rs | 6 +- tests/builder/default_vals.rs | 14 +- tests/builder/delimiters.rs | 16 +- tests/builder/derive_order.rs | 126 ++-- tests/builder/double_require.rs | 5 +- tests/builder/empty_values.rs | 22 +- tests/builder/env.rs | 34 +- tests/builder/error.rs | 2 + tests/builder/flag_subcommands.rs | 14 +- tests/builder/flags.rs | 8 +- tests/builder/global_args.rs | 15 +- tests/builder/grouped_values.rs | 22 +- tests/builder/groups.rs | 18 +- tests/builder/help.rs | 132 +++-- tests/builder/help_env.rs | 10 +- tests/builder/hidden_args.rs | 10 +- tests/builder/ignore_errors.rs | 4 +- tests/builder/indices.rs | 20 +- tests/builder/multiple_values.rs | 53 +- tests/builder/opts.rs | 32 +- tests/builder/positionals.rs | 8 +- tests/builder/possible_values.rs | 34 +- tests/builder/propagate_globals.rs | 2 +- tests/builder/require.rs | 195 ++++--- tests/builder/subcommands.rs | 10 +- tests/builder/unicode.rs | 2 +- tests/builder/utf8.rs | 47 +- 62 files changed, 1191 insertions(+), 866 deletions(-) diff --git a/clap_bench/benches/03_complex.rs b/clap_bench/benches/03_complex.rs index 9306894e4c8..a1dcebfd45b 100644 --- a/clap_bench/benches/03_complex.rs +++ b/clap_bench/benches/03_complex.rs @@ -57,7 +57,6 @@ pub fn build_from_builder(c: &mut Criterion) { .help("tests options") .short('o') .long("option") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append), ) @@ -82,7 +81,7 @@ pub fn build_from_builder(c: &mut Criterion) { .help("tests long options with exclusions") .conflicts_with("option") .requires("positional2") - .takes_value(true) + .action(ArgAction::Set) .long("long-option-2"), ) .arg( @@ -94,13 +93,12 @@ pub fn build_from_builder(c: &mut Criterion) { Arg::new("option3") .short('O') .long("Option") - .takes_value(true) + .action(ArgAction::Set) .help("tests options with specific value sets") .value_parser(OPT3_VALS), ) .arg( Arg::new("positional3") - .takes_value(true) .multiple_values(true) .help("tests positionals with specific values") .index(4) @@ -115,7 +113,6 @@ pub fn build_from_builder(c: &mut Criterion) { .arg( Arg::new("multvalsmo") .long("multvalsmo") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .help("Tests multiple values, not mult occs") @@ -124,7 +121,6 @@ pub fn build_from_builder(c: &mut Criterion) { .arg( Arg::new("minvals") .long("minvals2") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .help("Tests 2 min vals") @@ -133,7 +129,6 @@ pub fn build_from_builder(c: &mut Criterion) { .arg( Arg::new("maxvals") .long("maxvals3") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .help("Tests 3 max vals") @@ -148,7 +143,6 @@ pub fn build_from_builder(c: &mut Criterion) { Arg::new("scoption") .short('o') .long("option") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .help("tests options"), diff --git a/clap_bench/benches/04_new_help.rs b/clap_bench/benches/04_new_help.rs index 7de9dd48727..513c34374ec 100644 --- a/clap_bench/benches/04_new_help.rs +++ b/clap_bench/benches/04_new_help.rs @@ -47,7 +47,7 @@ fn app_example3<'c>() -> Command<'c> { .args(&[ Arg::new("config") .help("sets the config file to use") - .takes_value(true) + .action(ArgAction::Set) .short('c') .long("config"), Arg::new("input") @@ -118,7 +118,6 @@ fn app_example7<'c>() -> Command<'c> { .arg( Arg::new("input") .help("the input file to use") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .required(true) @@ -136,7 +135,6 @@ fn app_example8<'c>() -> Command<'c> { .arg( Arg::new("input") .help("the input file to use") - .takes_value(true) .multiple_values(true) .action(ArgAction::Append) .required(true) @@ -152,7 +150,7 @@ fn app_example10<'c>() -> Command<'c> { Arg::new("CONFIG") .help("The config file to use (default is \"config.json\")") .short('c') - .takes_value(true), + .action(ArgAction::Set), ) } diff --git a/clap_bench/benches/05_ripgrep.rs b/clap_bench/benches/05_ripgrep.rs index 10ab52c5245..3fd83b514e8 100644 --- a/clap_bench/benches/05_ripgrep.rs +++ b/clap_bench/benches/05_ripgrep.rs @@ -323,13 +323,12 @@ where "type-list", "version", ])) - .arg(arg("path").takes_value(true).multiple_values(true)) + .arg(arg("path").multiple_values(true)) .arg( flag("regexp") .short('e') .allow_hyphen_values(true) .action(ArgAction::Append) - .takes_value(true) .value_name("pattern"), ) .arg( @@ -345,22 +344,16 @@ where .arg( flag("color") .value_name("WHEN") - .takes_value(true) + .action(ArgAction::Set) .hide_possible_values(true) .value_parser(["never", "auto", "always", "ansi"]), ) - .arg( - flag("colors") - .value_name("SPEC") - .action(ArgAction::Append) - .takes_value(true), - ) + .arg(flag("colors").value_name("SPEC").action(ArgAction::Append)) .arg(flag("fixed-strings").short('F')) .arg( flag("glob") .short('g') .action(ArgAction::Append) - .takes_value(true) .value_name("GLOB"), ) .arg(flag("ignore-case").short('i')) @@ -371,14 +364,12 @@ where flag("type") .short('t') .action(ArgAction::Append) - .takes_value(true) .value_name("TYPE"), ) .arg( flag("type-not") .short('T') .action(ArgAction::Append) - .takes_value(true) .value_name("TYPE"), ) .arg(flag("unrestricted").short('u').action(ArgAction::Append)) diff --git a/clap_bench/benches/06_rustup.rs b/clap_bench/benches/06_rustup.rs index 8617498efd4..127c69f0151 100644 --- a/clap_bench/benches/06_rustup.rs +++ b/clap_bench/benches/06_rustup.rs @@ -2,7 +2,7 @@ // // CLI used is from rustup 408ed84f0e50511ed44a405dd91365e5da588790 -use clap::{Arg, ArgGroup, Command}; +use clap::{Arg, ArgAction, ArgGroup, Command}; use criterion::{criterion_group, criterion_main, Criterion}; pub fn build_rustup(c: &mut Criterion) { @@ -105,31 +105,51 @@ fn build_cli() -> Command<'static> { .subcommand( Command::new("list") .about("List installed and available targets") - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("add") .about("Add a target to a Rust toolchain") .arg(Arg::new("target").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("remove") .about("Remove a target from a Rust toolchain") .arg(Arg::new("target").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("install") .hide(true) // synonym for 'add' .arg(Arg::new("target").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("uninstall") .hide(true) // synonym for 'remove' .arg(Arg::new("target").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ), ) .subcommand( @@ -138,21 +158,33 @@ fn build_cli() -> Command<'static> { .subcommand( Command::new("list") .about("List installed and available components") - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("add") .about("Add a component to a Rust toolchain") .arg(Arg::new("component").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)) - .arg(Arg::new("target").long("target").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ) + .arg(Arg::new("target").long("target").action(ArgAction::Set)), ) .subcommand( Command::new("remove") .about("Remove a component from a Rust toolchain") .arg(Arg::new("component").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)) - .arg(Arg::new("target").long("target").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ) + .arg(Arg::new("target").long("target").action(ArgAction::Set)), ), ) .subcommand( @@ -172,7 +204,7 @@ fn build_cli() -> Command<'static> { .arg( Arg::new("path") .long("path") - .takes_value(true) + .action(ArgAction::Set) .help("Path to the directory"), ) .arg( @@ -190,7 +222,7 @@ fn build_cli() -> Command<'static> { Command::new("remove") .hide(true) // synonym for 'unset' .about("Remove the override toolchain for a directory") - .arg(Arg::new("path").long("path").takes_value(true)) + .arg(Arg::new("path").long("path").action(ArgAction::Set)) .arg( Arg::new("nonexistent") .long("nonexistent") @@ -204,12 +236,7 @@ fn build_cli() -> Command<'static> { .after_help(RUN_HELP) .trailing_var_arg(true) .arg(Arg::new("toolchain").required(true)) - .arg( - Arg::new("command") - .required(true) - .takes_value(true) - .multiple_values(true), - ), + .arg(Arg::new("command").required(true).multiple_values(true)), ) .subcommand( Command::new("which") @@ -236,7 +263,11 @@ fn build_cli() -> Command<'static> { Command::new("man") .about("View the man page for a given command") .arg(Arg::new("command").required(true)) - .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), + .arg( + Arg::new("toolchain") + .long("toolchain") + .action(ArgAction::Set), + ), ) .subcommand( Command::new("self") diff --git a/clap_complete/examples/completion.rs b/clap_complete/examples/completion.rs index 7fd5350b183..5dd5b3f9361 100644 --- a/clap_complete/examples/completion.rs +++ b/clap_complete/examples/completion.rs @@ -68,7 +68,6 @@ fn build_cli() -> Command<'static> { ) .arg( Arg::new("command_with_args") - .takes_value(true) .multiple_values(true) .value_hint(ValueHint::CommandWithArguments), ) diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/generator/mod.rs index b33ce481beb..1537673aaa8 100644 --- a/clap_complete/src/generator/mod.rs +++ b/clap_complete/src/generator/mod.rs @@ -83,9 +83,7 @@ pub trait Generator { /// /// ``` /// // src/cli.rs -/// -/// use clap::{Command, Arg}; -/// +/// # use clap::{Command, Arg, ArgAction}; /// pub fn build_cli() -> Command<'static> { /// Command::new("compl") /// .about("Tests completions") @@ -95,7 +93,7 @@ pub trait Generator { /// .about("tests things") /// .arg(Arg::new("case") /// .long("case") -/// .takes_value(true) +/// .action(ArgAction::Set) /// .help("the case to test"))) /// } /// ``` diff --git a/clap_complete/src/generator/utils.rs b/clap_complete/src/generator/utils.rs index 502f826d9dc..9364d79b36d 100644 --- a/clap_complete/src/generator/utils.rs +++ b/clap_complete/src/generator/utils.rs @@ -141,6 +141,7 @@ pub fn possible_values<'help>(a: &Arg<'help>) -> Option Command<'static> { @@ -152,6 +153,7 @@ mod tests { .short_alias('c') .visible_short_alias('p') .long("file") + .action(ArgAction::SetTrue) .visible_alias("path"), ), ) diff --git a/clap_complete/src/lib.rs b/clap_complete/src/lib.rs index de00eafb4bf..508008f2a57 100644 --- a/clap_complete/src/lib.rs +++ b/clap_complete/src/lib.rs @@ -22,7 +22,7 @@ //! ## Example //! //! ```rust,no_run -//! use clap::{Command, Arg, ValueHint, value_parser}; +//! use clap::{Command, Arg, ValueHint, value_parser, ArgAction}; //! use clap_complete::{generate, Generator, Shell}; //! use std::io; //! @@ -35,7 +35,7 @@ //! .arg( //! Arg::new("generator") //! .long("generate") -//! .takes_value(true) +//! .action(ArgAction::Set) //! .value_parser(value_parser!(Shell)), //! ) //! } diff --git a/clap_complete/tests/common.rs b/clap_complete/tests/common.rs index f2200cbd8dd..d40fb5f15c6 100644 --- a/clap_complete/tests/common.rs +++ b/clap_complete/tests/common.rs @@ -1,7 +1,17 @@ pub fn basic_command(name: &'static str) -> clap::Command<'static> { clap::Command::new(name) - .arg(clap::Arg::new("config").short('c').global(true)) - .arg(clap::Arg::new("v").short('v').conflicts_with("config")) + .arg( + clap::Arg::new("config") + .short('c') + .global(true) + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("v") + .short('v') + .conflicts_with("config") + .action(clap::ArgAction::SetTrue), + ) .subcommand( clap::Command::new("test").about("Subcommand").arg( clap::Arg::new("debug") @@ -35,7 +45,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("test").about("tests things").arg( clap::Arg::new("case") .long("case") - .takes_value(true) + .action(clap::ArgAction::Set) .help("the case to test"), ), ) @@ -50,15 +60,11 @@ pub fn special_commands_command(name: &'static str) -> clap::Command<'static> { clap::Arg::new("config") .long("config") .hide(true) - .takes_value(true) + .action(clap::ArgAction::Set) .require_equals(true) .help("the other case to test"), ) - .arg( - clap::Arg::new("path") - .takes_value(true) - .multiple_values(true), - ), + .arg(clap::Arg::new("path").multiple_values(true)), ) .subcommand(clap::Command::new("some-cmd-with-hyphens").alias("hyphen")) .subcommand(clap::Command::new("some-hidden-cmd").hide(true)) @@ -70,31 +76,37 @@ pub fn quoting_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("single-quotes") .long("single-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be 'always', 'auto', or 'never'"), ) .arg( clap::Arg::new("double-quotes") .long("double-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be \"always\", \"auto\", or \"never\""), ) .arg( clap::Arg::new("backticks") .long("backticks") + .action(clap::ArgAction::SetTrue) .help("For more information see `echo test`"), ) .arg( clap::Arg::new("backslash") .long("backslash") + .action(clap::ArgAction::SetTrue) .help("Avoid '\\n'"), ) .arg( clap::Arg::new("brackets") .long("brackets") + .action(clap::ArgAction::SetTrue) .help("List packages [filter]"), ) .arg( clap::Arg::new("expansions") .long("expansions") + .action(clap::ArgAction::SetTrue) .help("Execute the shell command with $SHELL"), ) .subcommands([ @@ -117,6 +129,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .short('f') .visible_short_alias('F') .long("flag") + .action(clap::ArgAction::SetTrue) .visible_alias("flg") .help("cmd flag"), ) @@ -127,7 +140,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .long("option") .visible_alias("opt") .help("cmd option") - .takes_value(true), + .action(clap::ArgAction::Set), ) .arg(clap::Arg::new("positional")) } @@ -140,7 +153,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("sub_cmd").about("sub-subcommand").arg( clap::Arg::new("config") .long("config") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")]) .help("the other case to test"), ), @@ -154,7 +167,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("choice") .long("choice") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser(["bash", "fish", "zsh"]), ) .arg( @@ -204,7 +217,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { ) .arg( clap::Arg::new("command_with_args") - .takes_value(true) + .action(clap::ArgAction::Set) .multiple_values(true) .value_hint(clap::ValueHint::CommandWithArguments), ) diff --git a/clap_complete_fig/tests/common.rs b/clap_complete_fig/tests/common.rs index f2200cbd8dd..d40fb5f15c6 100644 --- a/clap_complete_fig/tests/common.rs +++ b/clap_complete_fig/tests/common.rs @@ -1,7 +1,17 @@ pub fn basic_command(name: &'static str) -> clap::Command<'static> { clap::Command::new(name) - .arg(clap::Arg::new("config").short('c').global(true)) - .arg(clap::Arg::new("v").short('v').conflicts_with("config")) + .arg( + clap::Arg::new("config") + .short('c') + .global(true) + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("v") + .short('v') + .conflicts_with("config") + .action(clap::ArgAction::SetTrue), + ) .subcommand( clap::Command::new("test").about("Subcommand").arg( clap::Arg::new("debug") @@ -35,7 +45,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("test").about("tests things").arg( clap::Arg::new("case") .long("case") - .takes_value(true) + .action(clap::ArgAction::Set) .help("the case to test"), ), ) @@ -50,15 +60,11 @@ pub fn special_commands_command(name: &'static str) -> clap::Command<'static> { clap::Arg::new("config") .long("config") .hide(true) - .takes_value(true) + .action(clap::ArgAction::Set) .require_equals(true) .help("the other case to test"), ) - .arg( - clap::Arg::new("path") - .takes_value(true) - .multiple_values(true), - ), + .arg(clap::Arg::new("path").multiple_values(true)), ) .subcommand(clap::Command::new("some-cmd-with-hyphens").alias("hyphen")) .subcommand(clap::Command::new("some-hidden-cmd").hide(true)) @@ -70,31 +76,37 @@ pub fn quoting_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("single-quotes") .long("single-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be 'always', 'auto', or 'never'"), ) .arg( clap::Arg::new("double-quotes") .long("double-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be \"always\", \"auto\", or \"never\""), ) .arg( clap::Arg::new("backticks") .long("backticks") + .action(clap::ArgAction::SetTrue) .help("For more information see `echo test`"), ) .arg( clap::Arg::new("backslash") .long("backslash") + .action(clap::ArgAction::SetTrue) .help("Avoid '\\n'"), ) .arg( clap::Arg::new("brackets") .long("brackets") + .action(clap::ArgAction::SetTrue) .help("List packages [filter]"), ) .arg( clap::Arg::new("expansions") .long("expansions") + .action(clap::ArgAction::SetTrue) .help("Execute the shell command with $SHELL"), ) .subcommands([ @@ -117,6 +129,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .short('f') .visible_short_alias('F') .long("flag") + .action(clap::ArgAction::SetTrue) .visible_alias("flg") .help("cmd flag"), ) @@ -127,7 +140,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .long("option") .visible_alias("opt") .help("cmd option") - .takes_value(true), + .action(clap::ArgAction::Set), ) .arg(clap::Arg::new("positional")) } @@ -140,7 +153,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("sub_cmd").about("sub-subcommand").arg( clap::Arg::new("config") .long("config") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")]) .help("the other case to test"), ), @@ -154,7 +167,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("choice") .long("choice") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser(["bash", "fish", "zsh"]), ) .arg( @@ -204,7 +217,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { ) .arg( clap::Arg::new("command_with_args") - .takes_value(true) + .action(clap::ArgAction::Set) .multiple_values(true) .value_hint(clap::ValueHint::CommandWithArguments), ) diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index 6f3a4bd64fe..fecb72f4789 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -250,7 +250,6 @@ pub fn gen_augment( let implicit_methods = match **ty { Ty::Option => { quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) #value_parser #action @@ -258,7 +257,6 @@ pub fn gen_augment( } Ty::OptionOption => quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) .min_values(0) .max_values(1) @@ -270,7 +268,6 @@ pub fn gen_augment( Ty::OptionVec => { if attrs.is_positional() { quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) .multiple_values(true) // action won't be sufficient for getting multiple #value_parser @@ -278,7 +275,6 @@ pub fn gen_augment( } } else { quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) #value_parser #action @@ -289,7 +285,6 @@ pub fn gen_augment( Ty::Vec => { if attrs.is_positional() { quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) .multiple_values(true) // action won't be sufficient for getting multiple #value_parser @@ -297,7 +292,6 @@ pub fn gen_augment( } } else { quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) #value_parser #action @@ -312,7 +306,6 @@ pub fn gen_augment( // otherwise we'll report an "arg required" error when unwrapping. let action_value = action.args(); quote_spanned! { ty.span()=> - .takes_value(true) .value_name(#value_name) .required(#required && #action_value.takes_values()) #value_parser diff --git a/clap_mangen/examples/man.rs b/clap_mangen/examples/man.rs index 55a4107c459..3af6fae97c7 100644 --- a/clap_mangen/examples/man.rs +++ b/clap_mangen/examples/man.rs @@ -20,7 +20,6 @@ And a few newlines.", arg!(-c --config "Sets a custom config file") .long_help("Some more text about how to set a custom config file") .required(false) - .takes_value(true) .default_value("config.toml") .env("CONFIG_FILE"), ) diff --git a/clap_mangen/tests/common.rs b/clap_mangen/tests/common.rs index 3b8bcdc3cfb..874f1be6eca 100644 --- a/clap_mangen/tests/common.rs +++ b/clap_mangen/tests/common.rs @@ -1,11 +1,23 @@ pub fn basic_command(name: &'static str) -> clap::Command<'static> { clap::Command::new(name) - .arg(clap::Arg::new("config").short('c').global(true)) - .arg(clap::Arg::new("v").short('v').conflicts_with("config")) + .arg( + clap::Arg::new("config") + .short('c') + .global(true) + .action(clap::ArgAction::SetTrue), + ) + .arg( + clap::Arg::new("v") + .short('v') + .conflicts_with("config") + .action(clap::ArgAction::SetTrue), + ) .subcommand( - clap::Command::new("test") - .about("Subcommand") - .arg(clap::Arg::new("debug").short('d')), + clap::Command::new("test").about("Subcommand").arg( + clap::Arg::new("debug") + .short('d') + .action(clap::ArgAction::Count), + ), ) } @@ -21,6 +33,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> { ) .arg( clap::Arg::new("config") + .action(clap::ArgAction::Count) .help("some config file") .short('c') .visible_short_alias('C') @@ -32,7 +45,7 @@ pub fn feature_sample_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("test").about("tests things").arg( clap::Arg::new("case") .long("case") - .takes_value(true) + .action(clap::ArgAction::Set) .help("the case to test"), ), ) @@ -46,7 +59,7 @@ pub fn special_commands_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("config") .long("config") - .takes_value(true) + .action(clap::ArgAction::Set) .help("the other case to test"), ), ) @@ -59,31 +72,37 @@ pub fn quoting_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("single-quotes") .long("single-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be 'always', 'auto', or 'never'"), ) .arg( clap::Arg::new("double-quotes") .long("double-quotes") + .action(clap::ArgAction::SetTrue) .help("Can be \"always\", \"auto\", or \"never\""), ) .arg( clap::Arg::new("backticks") .long("backticks") + .action(clap::ArgAction::SetTrue) .help("For more information see `echo test`"), ) .arg( clap::Arg::new("backslash") .long("backslash") + .action(clap::ArgAction::SetTrue) .help("Avoid '\\n'"), ) .arg( clap::Arg::new("brackets") .long("brackets") + .action(clap::ArgAction::SetTrue) .help("List packages [filter]"), ) .arg( clap::Arg::new("expansions") .long("expansions") + .action(clap::ArgAction::SetTrue) .help("Execute the shell command with $SHELL"), ) .subcommands([ @@ -106,6 +125,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .short('f') .visible_short_alias('F') .long("flag") + .action(clap::ArgAction::SetTrue) .visible_alias("flg") .help("cmd flag"), ) @@ -116,7 +136,7 @@ pub fn aliases_command(name: &'static str) -> clap::Command<'static> { .long("option") .visible_alias("opt") .help("cmd option") - .takes_value(true), + .action(clap::ArgAction::Set), ) .arg(clap::Arg::new("positional")) } @@ -129,7 +149,7 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> { clap::Command::new("sub_cmd").about("sub-subcommand").arg( clap::Arg::new("config") .long("config") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")]) .help("the other case to test"), ), @@ -143,7 +163,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { .arg( clap::Arg::new("choice") .long("choice") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser(["bash", "fish", "zsh"]), ) .arg( @@ -193,7 +213,7 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { ) .arg( clap::Arg::new("command_with_args") - .takes_value(true) + .action(clap::ArgAction::Set) .multiple_values(true) .value_hint(clap::ValueHint::CommandWithArguments), ) @@ -223,7 +243,11 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> { pub fn hidden_option_command(name: &'static str) -> clap::Command<'static> { clap::Command::new(name) - .arg(clap::Arg::new("config").long("config").takes_value(true)) + .arg( + clap::Arg::new("config") + .long("config") + .action(clap::ArgAction::Set), + ) .arg( clap::Arg::new("no-config") .long("no-config") @@ -238,7 +262,7 @@ pub fn env_value_command(name: &'static str) -> clap::Command<'static> { .short('c') .long_help("Set configuration file path") .required(false) - .takes_value(true) + .action(clap::ArgAction::Set) .default_value("config.toml") .env("CONFIG_FILE"), ) diff --git a/clap_mangen/tests/snapshots/feature_sample.bash.roff b/clap_mangen/tests/snapshots/feature_sample.bash.roff index 814b63d3941..20fe84ee168 100644 --- a/clap_mangen/tests/snapshots/feature_sample.bash.roff +++ b/clap_mangen/tests/snapshots/feature_sample.bash.roff @@ -15,7 +15,7 @@ Print help information /fB/-V/fR, /fB/-/-version/fR Print version information .TP -/fB/-c/fR, /fB/-/-config/fR [default: false] +/fB/-c/fR, /fB/-/-config/fR [default: 0] some config file .TP [/fIfile/fR] diff --git a/clap_mangen/tests/snapshots/special_commands.bash.roff b/clap_mangen/tests/snapshots/special_commands.bash.roff index 3191e55894b..cde4467aa74 100644 --- a/clap_mangen/tests/snapshots/special_commands.bash.roff +++ b/clap_mangen/tests/snapshots/special_commands.bash.roff @@ -15,7 +15,7 @@ Print help information /fB/-V/fR, /fB/-/-version/fR Print version information .TP -/fB/-c/fR, /fB/-/-config/fR [default: false] +/fB/-c/fR, /fB/-/-config/fR [default: 0] some config file .TP [/fIfile/fR] diff --git a/clap_mangen/tests/snapshots/sub_subcommands.bash.roff b/clap_mangen/tests/snapshots/sub_subcommands.bash.roff index c3d89db9bbc..0e8823864a6 100644 --- a/clap_mangen/tests/snapshots/sub_subcommands.bash.roff +++ b/clap_mangen/tests/snapshots/sub_subcommands.bash.roff @@ -15,7 +15,7 @@ Print help information /fB/-V/fR, /fB/-/-version/fR Print version information .TP -/fB/-c/fR, /fB/-/-config/fR [default: false] +/fB/-c/fR, /fB/-/-config/fR [default: 0] some config file .TP [/fIfile/fR] diff --git a/examples/derive_ref/flatten_hand_args.rs b/examples/derive_ref/flatten_hand_args.rs index faa7c0bbd51..303ad98a794 100644 --- a/examples/derive_ref/flatten_hand_args.rs +++ b/examples/derive_ref/flatten_hand_args.rs @@ -48,7 +48,12 @@ impl Args for CliArgs { .long("bar") .action(ArgAction::SetTrue), ) - .arg(Arg::new("quuz").short('q').long("quuz").takes_value(true)) + .arg( + Arg::new("quuz") + .short('q') + .long("quuz") + .action(ArgAction::Set), + ) } fn augment_args_for_update(cmd: Command<'_>) -> Command<'_> { cmd.arg( @@ -63,7 +68,12 @@ impl Args for CliArgs { .long("bar") .action(ArgAction::SetTrue), ) - .arg(Arg::new("quuz").short('q').long("quuz").takes_value(true)) + .arg( + Arg::new("quuz") + .short('q') + .long("quuz") + .action(ArgAction::Set), + ) } } diff --git a/examples/multicall-busybox.rs b/examples/multicall-busybox.rs index 2e7f976c1f7..1f0a981bb53 100644 --- a/examples/multicall-busybox.rs +++ b/examples/multicall-busybox.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use std::process::exit; -use clap::{value_parser, Arg, Command}; +use clap::{value_parser, Arg, ArgAction, Command}; fn applet_commands() -> [Command<'static>; 2] { [ @@ -23,7 +23,7 @@ fn main() { .long("install") .help("Install hardlinks for all subcommands in path") .exclusive(true) - .takes_value(true) + .action(ArgAction::Set) .default_missing_value("/usr/local/bin") .value_parser(value_parser!(PathBuf)) .use_value_delimiter(false), diff --git a/examples/pacman.rs b/examples/pacman.rs index 6a60a8bf5ca..6f02c30e0c8 100644 --- a/examples/pacman.rs +++ b/examples/pacman.rs @@ -21,7 +21,7 @@ fn main() { .long("search") .help("search locally installed packages for matching strings") .conflicts_with("info") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg( @@ -30,7 +30,7 @@ fn main() { .short('i') .conflicts_with("search") .help("view package information") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ), ) @@ -47,7 +47,7 @@ fn main() { .short('s') .long("search") .conflicts_with("info") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .help("search remote repositories for matching strings"), ) @@ -63,7 +63,7 @@ fn main() { Arg::new("package") .help("packages") .required_unless_present("search") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ), ) diff --git a/src/_derive/mod.rs b/src/_derive/mod.rs index 08ebd7eb4f0..43246261859 100644 --- a/src/_derive/mod.rs +++ b/src/_derive/mod.rs @@ -256,14 +256,14 @@ //! //! `clap` assumes some intent based on the type used: //! -//! | Type | Effect | Implies | -//! |---------------------|--------------------------------------|------------------------------------------------------------------| -//! | `bool` | flag | `.action(ArgAction::SetTrue) | -//! | `Option` | optional argument | `.takes_value(true).required(false)` | -//! | `Option>` | optional value for optional argument | `.takes_value(true).required(false).min_values(0).max_values(1)` | -//! | `T` | required argument | `.takes_value(true).required(!has_default)` | -//! | `Vec` | `0..` occurrences of argument | `.takes_value(true).required(false).multiple_occurrences(true)` | -//! | `Option>` | `0..` occurrences of argument | `.takes_value(true).required(false).multiple_occurrences(true)` | +//! | Type | Effect | Implies | +//! |---------------------|--------------------------------------|--------------------------------------------------------------------------| +//! | `bool` | flag | `.action(ArgAction::SetTrue) | +//! | `Option` | optional argument | `.action(ArgAction::Set).required(false)` | +//! | `Option>` | optional value for optional argument | `.action(ArgAction::Set).required(false).min_values(0).max_values(1)` | +//! | `T` | required argument | `.action(ArgAction::Set).required(!has_default)` | +//! | `Vec` | `0..` occurrences of argument | `.action(ArgAction::Append).required(false).multiple_occurrences(true)` | +//! | `Option>` | `0..` occurrences of argument | `.action(ArgAction::Append).required(false).multiple_occurrences(true)` | //! //! Notes: //! - For custom type behavior, you can override the implied attributes/settings and/or set additional ones diff --git a/src/bin/stdio-fixture.rs b/src/bin/stdio-fixture.rs index e3f34b41a22..3a60d1338d5 100644 --- a/src/bin/stdio-fixture.rs +++ b/src/bin/stdio-fixture.rs @@ -8,6 +8,7 @@ fn main() { clap::Arg::new("verbose") .long("verbose") .help("log") + .action(clap::ArgAction::SetTrue) .long_help("more log"), ); cmd.get_matches(); diff --git a/src/builder/arg.rs b/src/builder/arg.rs index f90fcd3a5ec..e9d13a2241b 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -36,12 +36,12 @@ use crate::INTERNAL_ERROR_MSG; /// # Examples /// /// ```rust -/// # use clap::{Arg, arg}; +/// # use clap::{Arg, arg, ArgAction}; /// // Using the traditional builder pattern and setting each option manually /// let cfg = Arg::new("config") /// .short('c') /// .long("config") -/// .takes_value(true) +/// .action(ArgAction::Set) /// .value_name("FILE") /// .help("Provides a config file to myprog"); /// // Using a usage string (setting a similar argument to the one above) @@ -94,7 +94,7 @@ impl<'help> Arg<'help> { /// The name is used to check whether or not the argument was used at /// runtime, get values, set relationships with other args, etc.. /// - /// **NOTE:** In the case of arguments that take values (i.e. [`Arg::takes_value(true)`]) + /// **NOTE:** In the case of arguments that take values (i.e. [`Arg::action(ArgAction::Set)`]) /// and positional arguments (i.e. those without a preceding `-` or `--`) the name will also /// be displayed when the user prints the usage/help information of the program. /// @@ -105,7 +105,7 @@ impl<'help> Arg<'help> { /// Arg::new("config") /// # ; /// ``` - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() pub fn new>(n: S) -> Self { Arg::default().id(n) } @@ -134,11 +134,11 @@ impl<'help> Arg<'help> { /// argument via a single hyphen (`-`) such as `-c`: /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("config") /// .short('c') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "-c", "file.toml" /// ]); @@ -172,11 +172,11 @@ impl<'help> Arg<'help> { /// Setting `long` allows using the argument via a double hyphen (`--`) such as `--config` /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--config", "file.toml" /// ]); @@ -198,12 +198,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .alias("alias") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--alias", "cool" /// ]); @@ -223,12 +223,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .short('t') /// .short_alias('e') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "-e", "cool" /// ]); @@ -306,12 +306,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .visible_alias("something-awesome") /// .long("test") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--something-awesome", "coffee" /// ]); @@ -331,12 +331,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .visible_short_alias('t') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "-t", "coffee" /// ]); @@ -433,12 +433,13 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .index(1)) /// .arg(Arg::new("debug") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .get_matches_from(vec![ /// "prog", "--debug", "fast" /// ]); @@ -487,9 +488,9 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::Arg; + /// # use clap::{Arg, ArgAction}; /// Arg::new("args") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .last(true) /// # ; /// ``` @@ -498,12 +499,12 @@ impl<'help> Arg<'help> { /// and requires that the `--` syntax be used to access it early. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("first")) /// .arg(Arg::new("second")) /// .arg(Arg::new("third") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .last(true)) /// .try_get_matches_from(vec![ /// "prog", "one", "--", "three" @@ -519,12 +520,12 @@ impl<'help> Arg<'help> { /// failing to use the `--` syntax results in an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("first")) /// .arg(Arg::new("second")) /// .arg(Arg::new("third") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .last(true)) /// .try_get_matches_from(vec![ /// "prog", "one", "two", "three" @@ -569,11 +570,11 @@ impl<'help> Arg<'help> { /// Setting required requires that the argument be used at runtime. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required(true) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .try_get_matches_from(vec![ /// "prog", "--config", "file.conf", @@ -585,11 +586,11 @@ impl<'help> Arg<'help> { /// Setting required and then *not* supplying that argument at runtime is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required(true) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .try_get_matches_from(vec![ /// "prog" @@ -628,10 +629,10 @@ impl<'help> Arg<'help> { /// required /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires("input") /// .long("config")) /// .arg(Arg::new("input")) @@ -645,10 +646,10 @@ impl<'help> Arg<'help> { /// Setting [`Arg::requires(name)`] and *not* supplying that argument is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires("input") /// .long("config")) /// .arg(Arg::new("input")) @@ -683,10 +684,10 @@ impl<'help> Arg<'help> { /// is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("exclusive") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .exclusive(true) /// .long("exclusive")) /// .arg(Arg::new("debug") @@ -797,11 +798,11 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--mode", "fast" /// ]); @@ -864,6 +865,7 @@ impl<'help> Arg<'help> { /// - or any other [`TypedValueParser`][crate::builder::TypedValueParser] implementation /// /// ```rust + /// # use clap::ArgAction; /// let mut cmd = clap::Command::new("raw") /// .arg( /// clap::Arg::new("color") @@ -875,14 +877,14 @@ impl<'help> Arg<'help> { /// clap::Arg::new("hostname") /// .long("hostname") /// .value_parser(clap::builder::NonEmptyStringValueParser::new()) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required(true) /// ) /// .arg( /// clap::Arg::new("port") /// .long("port") /// .value_parser(clap::value_parser!(u16).range(3000..)) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required(true) /// ); /// @@ -965,10 +967,10 @@ impl<'help> Arg<'help> { /// An example with options /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .short('F')) /// .get_matches_from(vec![ @@ -983,10 +985,10 @@ impl<'help> Arg<'help> { /// Although `multiple_values` has been specified, the last argument still wins /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .short('F')) /// .get_matches_from(vec![ @@ -1002,10 +1004,10 @@ impl<'help> Arg<'help> { /// argument. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .short('F')) /// .arg(Arg::new("word")) @@ -1030,7 +1032,7 @@ impl<'help> Arg<'help> { /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .action(ArgAction::Append) /// .short('F')) /// .arg(Arg::new("word")) @@ -1050,7 +1052,7 @@ impl<'help> Arg<'help> { /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .action(ArgAction::Append) /// .short('F')) /// .arg(Arg::new("word")) @@ -1085,7 +1087,7 @@ impl<'help> Arg<'help> { /// `.number_of_values(3)`, and this argument wouldn't be satisfied unless the user provided /// 3 and only 3 values. /// - /// **NOTE:** implicitly sets [`Arg::takes_value(true)`] and [`Arg::multiple_values(true)`]. + /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`] and [`Arg::multiple_values(true)`]. /// /// # Examples /// @@ -1099,10 +1101,10 @@ impl<'help> Arg<'help> { /// Not supplying the correct number of values is an error /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .number_of_values(2) /// .short('F')) /// .try_get_matches_from(vec![ @@ -1137,10 +1139,10 @@ impl<'help> Arg<'help> { /// Supplying less than the maximum number of values is allowed /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .max_values(3) /// .short('F')) /// .try_get_matches_from(vec![ @@ -1156,10 +1158,10 @@ impl<'help> Arg<'help> { /// Supplying more than the maximum number of values is an error /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .max_values(2) /// .short('F')) /// .try_get_matches_from(vec![ @@ -1200,10 +1202,10 @@ impl<'help> Arg<'help> { /// Supplying more than the minimum number of values is allowed /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .min_values(2) /// .short('F')) /// .try_get_matches_from(vec![ @@ -1219,10 +1221,10 @@ impl<'help> Arg<'help> { /// Supplying less than the minimum number of values is an error /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("file") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .min_values(2) /// .short('F')) /// .try_get_matches_from(vec![ @@ -1247,7 +1249,7 @@ impl<'help> Arg<'help> { /// using, such as `FILE`, `INTERFACE`, etc. Although not required, it's somewhat convention to /// use all capital letters for the value name. /// - /// **NOTE:** implicitly sets [`Arg::takes_value(true)`] + /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`] /// /// # Examples /// @@ -1285,7 +1287,7 @@ impl<'help> Arg<'help> { /// ``` /// [option]: Arg::takes_value() /// [positional]: Arg::index() - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() #[inline] #[must_use] pub fn value_name(self, name: &'help str) -> Self { @@ -1306,7 +1308,7 @@ impl<'help> Arg<'help> { /// **Pro Tip:** It may help to use [`Arg::next_line_help(true)`] if there are long, or /// multiple value names in order to not throw off the help text alignment of all options. /// - /// **NOTE:** implicitly sets [`Arg::takes_value(true)`] and [`Arg::multiple_values(true)`]. + /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`] and [`Arg::multiple_values(true)`]. /// /// # Examples /// @@ -1343,7 +1345,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::next_line_help(true)`]: Arg::next_line_help() /// [`Arg::number_of_values`]: Arg::number_of_values() - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::multiple_values(true)`]: Arg::multiple_values() #[must_use] pub fn value_names(mut self, names: &[&'help str]) -> Self { @@ -1355,7 +1357,7 @@ impl<'help> Arg<'help> { /// /// See [`ValueHint`][crate::ValueHint] for more information. /// - /// **NOTE:** implicitly sets [`Arg::takes_value(true)`]. + /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`]. /// /// For example, to take a username as argument: /// @@ -1370,12 +1372,12 @@ impl<'help> Arg<'help> { /// To take a full command line and its arguments (for example, when writing a command wrapper): /// /// ``` - /// # use clap::{Command, Arg, ValueHint}; + /// # use clap::{Command, Arg, ValueHint, ArgAction}; /// Command::new("prog") /// .trailing_var_arg(true) /// .arg( /// Arg::new("command") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .value_hint(ValueHint::CommandWithArguments) /// ); @@ -1401,11 +1403,11 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("pv") /// .arg(Arg::new("option") /// .long("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .ignore_case(true) /// .value_parser(["test123"])) /// .get_matches_from(vec![ @@ -1418,12 +1420,12 @@ impl<'help> Arg<'help> { /// This setting also works when multiple values can be defined: /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("pv") /// .arg(Arg::new("option") /// .short('o') /// .long("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .ignore_case(true) /// .multiple_values(true) /// .value_parser(["test123", "test321"])) @@ -1463,10 +1465,10 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("pat") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .allow_hyphen_values(true) /// .long("pattern")) /// .get_matches_from(vec![ @@ -1480,10 +1482,10 @@ impl<'help> Arg<'help> { /// hyphen is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("pat") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("pattern")) /// .try_get_matches_from(vec![ /// "prog", "--pattern", "-file" @@ -1515,10 +1517,10 @@ impl<'help> Arg<'help> { /// it and the associated value. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .require_equals(true) /// .long("config")) /// .try_get_matches_from(vec![ @@ -1532,10 +1534,10 @@ impl<'help> Arg<'help> { /// error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .require_equals(true) /// .long("config")) /// .try_get_matches_from(vec![ @@ -1572,12 +1574,12 @@ impl<'help> Arg<'help> { /// The following example shows the default behavior. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let delims = Command::new("prog") /// .arg(Arg::new("option") /// .long("option") /// .use_value_delimiter(true) - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--option=val1,val2,val3", /// ]); @@ -1589,11 +1591,11 @@ impl<'help> Arg<'help> { /// behavior /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let nodelims = Command::new("prog") /// .arg(Arg::new("option") /// .long("option") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--option=val1,val2,val3", /// ]); @@ -1621,7 +1623,7 @@ impl<'help> Arg<'help> { /// /// **NOTE:** implicitly sets [`Arg::use_value_delimiter(true)`] /// - /// **NOTE:** implicitly sets [`Arg::takes_value(true)`] + /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`] /// /// # Examples /// @@ -1639,7 +1641,7 @@ impl<'help> Arg<'help> { /// assert_eq!(m.get_many::("config").unwrap().collect::>(), ["val1", "val2", "val3"]) /// ``` /// [`Arg::use_value_delimiter(true)`]: Arg::use_value_delimiter() - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() #[inline] #[must_use] pub fn value_delimiter(mut self, d: char) -> Self { @@ -1667,11 +1669,11 @@ impl<'help> Arg<'help> { /// everything works in this first example, as we use a delimiter, as expected. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let delims = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .use_value_delimiter(true) /// .require_value_delimiter(true) /// .multiple_values(true)) @@ -1686,11 +1688,11 @@ impl<'help> Arg<'help> { /// In this next example, we will *not* use a delimiter. Notice it's now an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .use_value_delimiter(true) /// .require_value_delimiter(true)) /// .try_get_matches_from(vec![ @@ -1710,11 +1712,11 @@ impl<'help> Arg<'help> { /// is *not* an error. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let delims = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true)) /// .get_matches_from(vec![ /// "prog", "-o", "val1", "val2", "val3", @@ -1749,9 +1751,9 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// Arg::new("vals") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .value_terminator(";") /// # ; @@ -1761,10 +1763,10 @@ impl<'help> Arg<'help> { /// to perform them /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("cmds") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .allow_hyphen_values(true) /// .value_terminator(";")) @@ -1804,10 +1806,10 @@ impl<'help> Arg<'help> { /// may not be exactly what you are expecting and using [`crate::Command::trailing_var_arg`] /// may be more appropriate. /// - /// **NOTE:** Implicitly sets [`Arg::takes_value(true)`] [`Arg::multiple_values(true)`], + /// **NOTE:** Implicitly sets [`Arg::action(ArgAction::Set)`] [`Arg::multiple_values(true)`], /// [`Arg::allow_hyphen_values(true)`], and [`Arg::last(true)`] when set to `true`. /// - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::multiple_values(true)`]: Arg::multiple_values() /// [`Arg::allow_hyphen_values(true)`]: Arg::allow_hyphen_values() /// [`Arg::last(true)`]: Arg::last() @@ -1838,7 +1840,7 @@ impl<'help> Arg<'help> { /// at runtime, nor were the conditions met for `Arg::default_value_if`, the `Arg::default_value` /// will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::takes_value(true)`]. + /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. /// /// # Examples /// @@ -1876,7 +1878,7 @@ impl<'help> Arg<'help> { /// assert_eq!(m.value_source("opt"), Some(ValueSource::CommandLine)); /// ``` /// [`ArgMatches::occurrences_of`]: crate::ArgMatches::occurrences_of() - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`ArgMatches::contains_id`]: crate::ArgMatches::contains_id() /// [`Arg::default_value_if`]: Arg::default_value_if() #[inline] @@ -2008,7 +2010,7 @@ impl<'help> Arg<'help> { /// assert_eq!(m.value_source("create"), Some(ValueSource::CommandLine)); /// ``` /// - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::default_value`]: Arg::default_value() #[inline] #[must_use] @@ -2059,14 +2061,14 @@ impl<'help> Arg<'help> { /// rules will apply. /// /// If user sets the argument in the environment: - /// - When [`Arg::takes_value(true)`] is not set, the flag is considered raised. - /// - When [`Arg::takes_value(true)`] is set, + /// - When [`Arg::action(ArgAction::Set)`] is not set, the flag is considered raised. + /// - When [`Arg::action(ArgAction::Set)`] is set, /// [`ArgMatches::get_one`][crate::ArgMatches::get_one] will /// return value of the environment variable. /// /// If user doesn't set the argument in the environment: - /// - When [`Arg::takes_value(true)`] is not set, the flag is considered off. - /// - When [`Arg::takes_value(true)`] is set, + /// - When [`Arg::action(ArgAction::Set)`] is not set, the flag is considered off. + /// - When [`Arg::action(ArgAction::Set)`] is set, /// [`ArgMatches::get_one`][crate::ArgMatches::get_one] will /// return the default specified. /// @@ -2076,7 +2078,7 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// /// env::set_var("MY_FLAG", "env"); /// @@ -2084,7 +2086,7 @@ impl<'help> Arg<'help> { /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog" /// ]); @@ -2134,7 +2136,7 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// /// env::set_var("MY_FLAG", "env"); /// @@ -2142,7 +2144,7 @@ impl<'help> Arg<'help> { /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "prog", "--flag", "opt" /// ]); @@ -2155,7 +2157,7 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// /// env::set_var("MY_FLAG", "env"); /// @@ -2163,7 +2165,7 @@ impl<'help> Arg<'help> { /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .default_value("default")) /// .get_matches_from(vec![ /// "prog" @@ -2176,7 +2178,7 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// /// env::set_var("MY_FLAG_MULTI", "env1,env2"); /// @@ -2184,7 +2186,7 @@ impl<'help> Arg<'help> { /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG_MULTI") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true) /// .use_value_delimiter(true)) /// .get_matches_from(vec![ @@ -2193,7 +2195,7 @@ impl<'help> Arg<'help> { /// /// assert_eq!(m.get_many::("flag").unwrap().collect::>(), vec!["env1", "env2"]); /// ``` - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::use_value_delimiter(true)`]: Arg::use_value_delimiter() #[cfg(feature = "env")] #[inline] @@ -2341,19 +2343,19 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name. /// // Args without a display_order have a value of 999 and are /// // displayed alphabetically with all other 999 valued args. /// .long("long-option") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .help("Some help and text")) /// .arg(Arg::new("b") /// .long("other-option") /// .short('O') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .display_order(1) // In order to force this arg to appear *first* /// // all we have to do is give it a value lower than 999. /// // Any other args with a value of 1 will be displayed @@ -2411,12 +2413,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .long("long-option-flag") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .next_line_help(true) /// .value_names(&["value1", "value2"]) /// .help("Some really long help and complex\n\ @@ -2508,12 +2510,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .value_parser(["fast", "slow"]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .hide_possible_values(true)); /// ``` /// If we were to run the above program with `--help` the `[values: fast, slow]` portion of @@ -2537,12 +2539,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("connect") /// .arg(Arg::new("host") /// .long("host") /// .default_value("localhost") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .hide_default_value(true)); /// /// ``` @@ -2566,12 +2568,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .env("MODE") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .hide_env(true)); /// ``` /// @@ -2595,12 +2597,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("connect") /// .arg(Arg::new("host") /// .long("host") /// .env("CONNECT") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .hide_env_values(true)); /// /// ``` @@ -2778,9 +2780,10 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// Arg::new("debug") /// .long("debug") + /// .action(ArgAction::SetTrue) /// .group("mode") /// # ; /// ``` @@ -2789,13 +2792,15 @@ impl<'help> Arg<'help> { /// was one of said arguments. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") + /// .action(ArgAction::SetTrue) /// .group("mode")) /// .arg(Arg::new("verbose") /// .long("verbose") + /// .action(ArgAction::SetTrue) /// .group("mode")) /// .get_matches_from(vec![ /// "prog", "--debug" @@ -2815,9 +2820,10 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// Arg::new("debug") /// .long("debug") + /// .action(ArgAction::SetTrue) /// .groups(&["mode", "verbosity"]) /// # ; /// ``` @@ -2826,13 +2832,15 @@ impl<'help> Arg<'help> { /// was one of said arguments. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") + /// .action(ArgAction::SetTrue) /// .groups(&["mode", "verbosity"])) /// .arg(Arg::new("verbose") /// .long("verbose") + /// .action(ArgAction::SetTrue) /// .groups(&["mode", "verbosity"])) /// .get_matches_from(vec![ /// "prog", "--debug" @@ -2862,17 +2870,18 @@ impl<'help> Arg<'help> { /// and `Arg::default_value_if`, and the user **did not** provide this arg at runtime, nor were /// the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::takes_value(true)`]. + /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. /// /// # Examples /// /// First we use the default value only if another arg is present at runtime. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("other") /// .long("other") /// .default_value_if("flag", None, Some("default"))) @@ -2886,10 +2895,11 @@ impl<'help> Arg<'help> { /// Next we run the same test, but without providing `--flag`. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("other") /// .long("other") /// .default_value_if("flag", Some("true"), Some("default"))) @@ -2903,10 +2913,10 @@ impl<'help> Arg<'help> { /// Now lets only use the default value if `--opt` contains the value `special`. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("opt") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("opt")) /// .arg(Arg::new("other") /// .long("other") @@ -2922,10 +2932,10 @@ impl<'help> Arg<'help> { /// default value. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("opt") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("opt")) /// .arg(Arg::new("other") /// .long("other") @@ -2941,10 +2951,11 @@ impl<'help> Arg<'help> { /// value of some other Arg. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("other") /// .long("other") /// .default_value("default") @@ -2955,7 +2966,7 @@ impl<'help> Arg<'help> { /// /// assert_eq!(m.get_one::("other"), None); /// ``` - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::default_value`]: Arg::default_value() #[must_use] pub fn default_value_if( @@ -2996,13 +3007,14 @@ impl<'help> Arg<'help> { /// First we use the default value only if another arg is present at runtime. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("opt") /// .long("opt") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .arg(Arg::new("other") /// .long("other") /// .default_value_ifs(&[ @@ -3019,10 +3031,11 @@ impl<'help> Arg<'help> { /// Next we run the same test, but without providing `--flag`. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("other") /// .long("other") /// .default_value_ifs(&[ @@ -3040,13 +3053,14 @@ impl<'help> Arg<'help> { /// true, only the first evaluated "wins" /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") /// .arg(Arg::new("flag") - /// .long("flag")) + /// .long("flag") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("opt") /// .long("opt") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .arg(Arg::new("other") /// .long("other") /// .default_value_ifs(&[ @@ -3059,7 +3073,7 @@ impl<'help> Arg<'help> { /// /// assert_eq!(m.get_one::("other").unwrap(), "default"); /// ``` - /// [`Arg::takes_value(true)`]: Arg::takes_value() + /// [`Arg::action(ArgAction::Set)`]: Arg::takes_value() /// [`Arg::default_value_if`]: Arg::default_value_if() #[must_use] pub fn default_value_ifs( @@ -3106,14 +3120,15 @@ impl<'help> Arg<'help> { /// but it's not an error because the `unless` arg has been supplied. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present("dbg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .try_get_matches_from(vec![ /// "prog", "--debug" /// ]); @@ -3124,11 +3139,11 @@ impl<'help> Arg<'help> { /// Setting `Arg::required_unless_present(name)` and *not* supplying `name` or this arg is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present("dbg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") /// .long("debug")) @@ -3168,17 +3183,18 @@ impl<'help> Arg<'help> { /// because *all* of the `names` args have been supplied. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_all(&["dbg", "infile"]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("infile") /// .short('i') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--debug", "-i", "file" /// ]); @@ -3190,17 +3206,18 @@ impl<'help> Arg<'help> { /// either *all* of `unless` args or the `self` arg is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_all(&["dbg", "infile"]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("infile") /// .short('i') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog" /// ]); @@ -3245,17 +3262,18 @@ impl<'help> Arg<'help> { /// have been supplied. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_any(&["dbg", "infile"]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("infile") /// .short('i') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--debug" /// ]); @@ -3267,17 +3285,18 @@ impl<'help> Arg<'help> { /// or this arg is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_any(&["dbg", "infile"]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("dbg") - /// .long("debug")) + /// .long("debug") + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("infile") /// .short('i') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog" /// ]); @@ -3311,15 +3330,15 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required_if_eq("other", "special") /// .long("config")) /// .arg(Arg::new("other") /// .long("other") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--other", "not-special" /// ]); @@ -3328,12 +3347,12 @@ impl<'help> Arg<'help> { /// /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required_if_eq("other", "special") /// .long("config")) /// .arg(Arg::new("other") /// .long("other") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--other", "special" /// ]); @@ -3344,12 +3363,12 @@ impl<'help> Arg<'help> { /// /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required_if_eq("other", "special") /// .long("config")) /// .arg(Arg::new("other") /// .long("other") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--other", "SPECIAL" /// ]); @@ -3359,13 +3378,13 @@ impl<'help> Arg<'help> { /// /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required_if_eq("other", "special") /// .long("config")) /// .arg(Arg::new("other") /// .long("other") /// .ignore_case(true) - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![ /// "prog", "--other", "SPECIAL" /// ]); @@ -3405,20 +3424,20 @@ impl<'help> Arg<'help> { /// anything other than `val`, this argument isn't required. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_any(&[ /// ("extra", "val"), /// ("option", "spec") /// ]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("extra") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("extra")) /// .arg(Arg::new("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("option")) /// .try_get_matches_from(vec![ /// "prog", "--option", "other" @@ -3431,20 +3450,20 @@ impl<'help> Arg<'help> { /// value of `val` but *not* using this arg is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_any(&[ /// ("extra", "val"), /// ("option", "spec") /// ]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("extra") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("extra")) /// .arg(Arg::new("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("option")) /// .try_get_matches_from(vec![ /// "prog", "--option", "spec" @@ -3485,20 +3504,20 @@ impl<'help> Arg<'help> { /// anything other than `val`, this argument isn't required. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_all(&[ /// ("extra", "val"), /// ("option", "spec") /// ]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("extra") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("extra")) /// .arg(Arg::new("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("option")) /// .try_get_matches_from(vec![ /// "prog", "--option", "spec" @@ -3511,20 +3530,20 @@ impl<'help> Arg<'help> { /// value of `val` but *not* using this arg is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_all(&[ /// ("extra", "val"), /// ("option", "spec") /// ]) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("config")) /// .arg(Arg::new("extra") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("extra")) /// .arg(Arg::new("option") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .long("option")) /// .try_get_matches_from(vec![ /// "prog", "--extra", "val", "--option", "spec" @@ -3561,10 +3580,10 @@ impl<'help> Arg<'help> { /// `val`, the other argument isn't required. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires_if("my.cfg", "other") /// .long("config")) /// .arg(Arg::new("other")) @@ -3579,10 +3598,10 @@ impl<'help> Arg<'help> { /// `arg` is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires_if("my.cfg", "input") /// .long("config")) /// .arg(Arg::new("input")) @@ -3624,10 +3643,10 @@ impl<'help> Arg<'help> { /// than `val`, `arg` isn't required. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires_ifs(&[ /// ("special.conf", "opt"), /// ("other.conf", "other"), @@ -3635,7 +3654,7 @@ impl<'help> Arg<'help> { /// .long("config")) /// .arg(Arg::new("opt") /// .long("option") - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .arg(Arg::new("other")) /// .try_get_matches_from(vec![ /// "prog", "--config", "special.conf" @@ -3677,10 +3696,10 @@ impl<'help> Arg<'help> { /// argument isn't required /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires("input") /// .long("config")) /// .arg(Arg::new("input")) @@ -3696,10 +3715,10 @@ impl<'help> Arg<'help> { /// error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .requires_all(&["input", "output"]) /// .long("config")) /// .arg(Arg::new("input")) @@ -3746,10 +3765,10 @@ impl<'help> Arg<'help> { /// Setting conflicting argument, and having both arguments present at runtime is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .conflicts_with("debug") /// .long("config")) /// .arg(Arg::new("debug") @@ -3796,10 +3815,10 @@ impl<'help> Arg<'help> { /// conflicting argument is an error. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("cfg") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .conflicts_with_all(&["debug", "input"]) /// .long("config")) /// .arg(Arg::new("debug") @@ -4572,53 +4591,57 @@ mod test { #[test] fn flag_display() { - let mut f = Arg::new("flg").action(ArgAction::Append); - f.long = Some("flag"); + let mut f = Arg::new("flg").long("flag").action(ArgAction::SetTrue); + f._build(); assert_eq!(f.to_string(), "--flag"); - let mut f2 = Arg::new("flg"); - f2.short = Some('f'); + let mut f2 = Arg::new("flg").short('f').action(ArgAction::SetTrue); + f2._build(); assert_eq!(f2.to_string(), "-f"); } #[test] fn flag_display_single_alias() { - let mut f = Arg::new("flg"); - f.long = Some("flag"); - f.aliases = vec![("als", true)]; + let mut f = Arg::new("flg") + .long("flag") + .visible_alias("als") + .action(ArgAction::SetTrue); + f._build(); assert_eq!(f.to_string(), "--flag") } #[test] fn flag_display_multiple_aliases() { - let mut f = Arg::new("flg"); - f.short = Some('f'); + let mut f = Arg::new("flg").short('f').action(ArgAction::SetTrue); f.aliases = vec![ ("alias_not_visible", false), ("f2", true), ("f3", true), ("f4", true), ]; + f._build(); + assert_eq!(f.to_string(), "-f"); } #[test] fn flag_display_single_short_alias() { - let mut f = Arg::new("flg"); - f.short = Some('a'); + let mut f = Arg::new("flg").short('a').action(ArgAction::SetTrue); f.short_aliases = vec![('b', true)]; + f._build(); assert_eq!(f.to_string(), "-a") } #[test] fn flag_display_multiple_short_aliases() { - let mut f = Arg::new("flg"); - f.short = Some('a'); + let mut f = Arg::new("flg").short('a').action(ArgAction::SetTrue); f.short_aliases = vec![('b', false), ('c', true), ('d', true), ('e', true)]; + f._build(); + assert_eq!(f.to_string(), "-a"); } @@ -4626,80 +4649,88 @@ mod test { #[test] fn option_display_multiple_occurrences() { - let o = Arg::new("opt") - .long("option") - .takes_value(true) - .action(ArgAction::Append); + let mut o = Arg::new("opt").long("option").action(ArgAction::Append); + o._build(); assert_eq!(o.to_string(), "--option "); } #[test] fn option_display_multiple_values() { - let o = Arg::new("opt") + let mut o = Arg::new("opt") .long("option") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true); + o._build(); assert_eq!(o.to_string(), "--option ..."); } #[test] fn option_display2() { - let o2 = Arg::new("opt").short('o').value_names(&["file", "name"]); + let mut o = Arg::new("opt") + .short('o') + .action(ArgAction::Set) + .value_names(&["file", "name"]); + o._build(); - assert_eq!(o2.to_string(), "-o "); + assert_eq!(o.to_string(), "-o "); } #[test] fn option_display3() { - let o2 = Arg::new("opt") + let mut o = Arg::new("opt") .short('o') - .takes_value(true) .multiple_values(true) + .action(ArgAction::Set) .value_names(&["file", "name"]); + o._build(); - assert_eq!(o2.to_string(), "-o "); + assert_eq!(o.to_string(), "-o "); } #[test] fn option_display_single_alias() { - let o = Arg::new("opt") - .takes_value(true) + let mut o = Arg::new("opt") .long("option") + .action(ArgAction::Set) .visible_alias("als"); + o._build(); assert_eq!(o.to_string(), "--option "); } #[test] fn option_display_multiple_aliases() { - let o = Arg::new("opt") + let mut o = Arg::new("opt") .long("option") - .takes_value(true) + .action(ArgAction::Set) .visible_aliases(&["als2", "als3", "als4"]) .alias("als_not_visible"); + o._build(); assert_eq!(o.to_string(), "--option "); } #[test] fn option_display_single_short_alias() { - let o = Arg::new("opt") - .takes_value(true) + let mut o = Arg::new("opt") .short('a') + .action(ArgAction::Set) .visible_short_alias('b'); + o._build(); assert_eq!(o.to_string(), "-a "); } #[test] fn option_display_multiple_short_aliases() { - let o = Arg::new("opt") + let mut o = Arg::new("opt") .short('a') - .takes_value(true) + .action(ArgAction::Set) .visible_short_aliases(&['b', 'c', 'd']) .short_alias('e'); + o._build(); assert_eq!(o.to_string(), "-a "); } @@ -4708,45 +4739,44 @@ mod test { #[test] fn positional_display_multiple_values() { - let p = Arg::new("pos") - .index(1) - .takes_value(true) - .multiple_values(true); + let mut p = Arg::new("pos").index(1).multiple_values(true); + p._build(); assert_eq!(p.to_string(), "..."); } #[test] fn positional_display_multiple_occurrences() { - let p = Arg::new("pos") - .index(1) - .takes_value(true) - .action(ArgAction::Append); + let mut p = Arg::new("pos").index(1).action(ArgAction::Append); + p._build(); assert_eq!(p.to_string(), "..."); } #[test] fn positional_display_required() { - let p2 = Arg::new("pos").index(1).required(true); + let mut p = Arg::new("pos").index(1).required(true); + p._build(); - assert_eq!(p2.to_string(), ""); + assert_eq!(p.to_string(), ""); } #[test] fn positional_display_val_names() { - let p2 = Arg::new("pos").index(1).value_names(&["file1", "file2"]); + let mut p = Arg::new("pos").index(1).value_names(&["file1", "file2"]); + p._build(); - assert_eq!(p2.to_string(), " "); + assert_eq!(p.to_string(), " "); } #[test] fn positional_display_val_names_req() { - let p2 = Arg::new("pos") + let mut p = Arg::new("pos") .index(1) .required(true) .value_names(&["file1", "file2"]); + p._build(); - assert_eq!(p2.to_string(), " "); + assert_eq!(p.to_string(), " "); } } diff --git a/src/builder/arg_group.rs b/src/builder/arg_group.rs index 42d23b76c30..02876d3e509 100644 --- a/src/builder/arg_group.rs +++ b/src/builder/arg_group.rs @@ -130,12 +130,14 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup}; + /// # use clap::{Command, Arg, ArgGroup, ArgAction}; /// let m = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .arg("flag") /// .arg("color")) @@ -157,12 +159,14 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup}; + /// # use clap::{Command, Arg, ArgGroup, ArgAction}; /// let m = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"])) /// .get_matches_from(vec!["myprog", "-f"]); @@ -188,12 +192,14 @@ impl<'help> ArgGroup<'help> { /// group /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup}; + /// # use clap::{Command, Arg, ArgGroup, ArgAction}; /// let m = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .multiple(true)) @@ -205,12 +211,14 @@ impl<'help> ArgGroup<'help> { /// an error if more than one of the args in the group was used. /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"])) /// .try_get_matches_from(vec!["myprog", "-f", "-c"]); @@ -244,12 +252,14 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .required(true)) @@ -281,14 +291,17 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .requires("debug")) @@ -318,16 +331,20 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("verb") - /// .short('v')) + /// .short('v') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .requires_all(&["debug", "verb"])) @@ -359,14 +376,17 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .conflicts_with("debug")) @@ -393,16 +413,20 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction}; /// let result = Command::new("myprog") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("color") - /// .short('c')) + /// .short('c') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("verb") - /// .short('v')) + /// .short('v') + /// .action(ArgAction::SetTrue)) /// .group(ArgGroup::new("req_flags") /// .args(&["flag", "color"]) /// .conflicts_with_all(&["debug", "verb"])) diff --git a/src/builder/command.rs b/src/builder/command.rs index 00bd90405b2..c78c2bd76bd 100644 --- a/src/builder/command.rs +++ b/src/builder/command.rs @@ -231,11 +231,12 @@ impl<'help> Command<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// /// let mut cmd = Command::new("foo") /// .arg(Arg::new("bar") - /// .short('b')) + /// .short('b') + /// .action(ArgAction::SetTrue)) /// .mut_arg("bar", |a| a.short('B')); /// /// let res = cmd.try_get_matches_from_mut(vec!["foo", "-b"]); @@ -1908,7 +1909,7 @@ impl<'help> Command<'help> { /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("format") /// .long("format") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .value_parser(["txt", "json"])) /// .replace("--save-all", &["--save-context", "--save-runtime", "--format=json"]) /// .get_matches_from(vec!["cmd", "--save-all"]); @@ -2112,13 +2113,13 @@ impl<'help> Command<'help> { /// Style number two from above: /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// // Assume there is an external subcommand named "subcmd" /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("foo")) /// .arg(Arg::new("bar")) - /// .arg(Arg::new("baz").takes_value(true).multiple_values(true)) + /// .arg(Arg::new("baz").action(ArgAction::Set).multiple_values(true)) /// .get_matches_from(vec![ /// "prog", "foo", "bar", "baz1", "baz2", "baz3" /// ]); @@ -2131,13 +2132,13 @@ impl<'help> Command<'help> { /// Now nofice if we don't specify `foo` or `baz` but use the `--` operator. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// // Assume there is an external subcommand named "subcmd" /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("foo")) /// .arg(Arg::new("bar")) - /// .arg(Arg::new("baz").takes_value(true).multiple_values(true)) + /// .arg(Arg::new("baz").action(ArgAction::Set).multiple_values(true)) /// .get_matches_from(vec![ /// "prog", "--", "baz1", "baz2", "baz3" /// ]); @@ -2829,12 +2830,12 @@ impl<'help> Command<'help> { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let cmd = Command::new("cmd").subcommand(Command::new("sub")).arg( /// Arg::new("arg") /// .long("arg") /// .multiple_values(true) - /// .takes_value(true), + /// .action(ArgAction::Set), /// ); /// /// let matches = cmd @@ -3805,10 +3806,10 @@ impl<'help> Command<'help> { // in the usage string don't get confused or left out. self.settings.set(AppSettings::DontCollapseArgsInUsage); } + a._build(); if hide_pv && a.is_takes_value_set() { a.settings.set(ArgSettings::HidePossibleValues); } - a._build(); if a.is_positional() && a.index.is_none() { a.index = Some(pos_counter); pos_counter += 1; @@ -4255,7 +4256,7 @@ To change `help`s short, call `cmd.arg(Arg::new(\"help\")...)`.", .arg( Arg::new("subcommand") .index(1) - .takes_value(true) + .action(ArgAction::Append) .multiple_values(true) .value_name("SUBCOMMAND") .help("The subcommand whose help message to display"), diff --git a/src/builder/possible_value.rs b/src/builder/possible_value.rs index 06bc2b4128d..79787534517 100644 --- a/src/builder/possible_value.rs +++ b/src/builder/possible_value.rs @@ -12,9 +12,9 @@ use crate::util::eq_ignore_case; /// # Examples /// /// ```rust -/// # use clap::{Arg, PossibleValue}; +/// # use clap::{Arg, PossibleValue, ArgAction}; /// let cfg = Arg::new("config") -/// .takes_value(true) +/// .action(ArgAction::Set) /// .value_name("FILE") /// .value_parser([ /// PossibleValue::new("fast"), diff --git a/src/builder/value_parser.rs b/src/builder/value_parser.rs index 397537c9f52..4cdc7c1aaac 100644 --- a/src/builder/value_parser.rs +++ b/src/builder/value_parser.rs @@ -29,14 +29,14 @@ use crate::parser::AnyValueId; /// clap::Arg::new("hostname") /// .long("hostname") /// .value_parser(clap::builder::NonEmptyStringValueParser::new()) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ) /// .arg( /// clap::Arg::new("port") /// .long("port") /// .value_parser(clap::value_parser!(u16).range(3000..)) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -269,7 +269,7 @@ impl ValueParser { /// clap::Arg::new("hostname") /// .long("hostname") /// .value_parser(clap::builder::NonEmptyStringValueParser::new()) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -311,7 +311,7 @@ impl From<_AnonymousValueParser> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(3000..4000) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -341,7 +341,7 @@ impl From> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(3000..=4000) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -371,7 +371,7 @@ impl From> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(3000..) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -401,7 +401,7 @@ impl From> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(..3000) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -431,7 +431,7 @@ impl From> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(..=3000) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -461,7 +461,7 @@ impl From> for ValueParser { /// clap::Arg::new("port") /// .long("port") /// .value_parser(..) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -1062,7 +1062,7 @@ where /// clap::Arg::new("port") /// .long("port") /// .value_parser(clap::value_parser!(u16).range(3000..)) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// @@ -1260,7 +1260,7 @@ impl + Clone + Send + Sync> Default for RangedI64V /// clap::Arg::new("port") /// .long("port") /// .value_parser(clap::value_parser!(u64).range(3000..)) -/// .takes_value(true) +/// .action(clap::ArgAction::Set) /// .required(true) /// ); /// diff --git a/src/derive.rs b/src/derive.rs index dae568faeec..7263f0783cf 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -58,7 +58,7 @@ use std::ffi::OsString; /// .long("name") /// .short('n') /// .help("An optional name") -/// .takes_value(true)); +/// .action(ArgAction::Set)); /// /// struct Context { /// verbose: bool, diff --git a/src/error/kind.rs b/src/error/kind.rs index 25691a7b43e..e25e01b9b71 100644 --- a/src/error/kind.rs +++ b/src/error/kind.rs @@ -60,10 +60,10 @@ pub enum ErrorKind { /// sign to provide values. /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let res = Command::new("prog") /// .arg(Arg::new("color") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .require_equals(true) /// .long("color")) /// .try_get_matches_from(vec!["prog", "--color", "red"]); @@ -137,11 +137,11 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let result = Command::new("prog") /// .arg(Arg::new("some_opt") /// .long("opt") - /// .takes_value(true) + /// .action(ArgAction::Set) /// .number_of_values(2)) /// .try_get_matches_from(vec!["prog", "--opt", "wrong"]); /// assert!(result.is_err()); @@ -158,13 +158,15 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// let result = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") + /// .action(ArgAction::SetTrue) /// .conflicts_with("color")) /// .arg(Arg::new("color") - /// .long("color")) + /// .long("color") + /// .action(ArgAction::SetTrue)) /// .try_get_matches_from(vec!["prog", "--debug", "--color"]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind(), ErrorKind::ArgumentConflict); @@ -222,13 +224,13 @@ pub enum ErrorKind { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{Command, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind, ArgAction}; /// # use std::os::unix::ffi::OsStringExt; /// # use std::ffi::OsString; /// let result = Command::new("prog") /// .arg(Arg::new("utf8") /// .short('u') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .try_get_matches_from(vec![OsString::from("myprog"), /// OsString::from("-u"), /// OsString::from_vec(vec![0xE9])]); diff --git a/src/macros.rs b/src/macros.rs index 18c78a18447..ae228713f41 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -207,7 +207,10 @@ macro_rules! arg_impl { if arg.get_id().is_empty() { arg = arg.id(long); } - arg.long(long).action($crate::ArgAction::SetTrue) + arg + .long(long) + .action($crate::ArgAction::SetTrue) + .takes_value(false) }) $($tail)* } @@ -229,7 +232,10 @@ macro_rules! arg_impl { if arg.get_id().is_empty() { arg = arg.id(long); } - arg.long(long).action($crate::ArgAction::SetTrue) + arg + .long(long) + .action($crate::ArgAction::SetTrue) + .takes_value(false) }) $($tail)* } @@ -247,7 +253,10 @@ macro_rules! arg_impl { debug_assert_eq!($arg.get_value_names(), None, "Flags should precede values"); debug_assert!(!matches!($arg.get_action(), $crate::ArgAction::Append), "Flags should precede `...`"); - $arg.short($crate::arg_impl! { @char $short }).action($crate::ArgAction::SetTrue) + $arg + .short($crate::arg_impl! { @char $short }) + .action($crate::ArgAction::SetTrue) + .takes_value(false) }) $($tail)* } @@ -265,7 +274,10 @@ macro_rules! arg_impl { debug_assert_eq!($arg.get_value_names(), None, "Flags should precede values"); debug_assert!(!matches!($arg.get_action(), $crate::ArgAction::Append), "Flags should precede `...`"); - $arg.short($crate::arg_impl! { @char $short }).action($crate::ArgAction::SetTrue) + $arg + .short($crate::arg_impl! { @char $short }) + .action($crate::ArgAction::SetTrue) + .takes_value(false) }) $($tail)* } @@ -285,13 +297,15 @@ macro_rules! arg_impl { let mut arg = $arg; arg = arg.required(true); - arg = arg.takes_value(true); let value_name = $crate::arg_impl! { @string $value_name }; if arg.get_id().is_empty() { arg = arg.id(value_name); } - arg.value_name(value_name).action($crate::ArgAction::Set) + arg + .value_name(value_name) + .action($crate::ArgAction::Set) + .takes_value(true) }) $($tail)* } @@ -311,13 +325,15 @@ macro_rules! arg_impl { let mut arg = $arg; arg = arg.required(true); - arg = arg.takes_value(true); let value_name = $crate::arg_impl! { @string $value_name }; if arg.get_id().is_empty() { arg = arg.id(value_name); } - arg.value_name(value_name).action($crate::ArgAction::Set) + arg + .value_name(value_name) + .action($crate::ArgAction::Set) + .takes_value(true) }) $($tail)* } @@ -341,13 +357,15 @@ macro_rules! arg_impl { } else { arg = arg.min_values(0).max_values(1); } - arg = arg.takes_value(true); let value_name = $crate::arg_impl! { @string $value_name }; if arg.get_id().is_empty() { arg = arg.id(value_name); } - arg.value_name(value_name).action($crate::ArgAction::Set) + arg + .value_name(value_name) + .action($crate::ArgAction::Set) + .takes_value(true) }) $($tail)* } @@ -371,13 +389,15 @@ macro_rules! arg_impl { } else { arg = arg.min_values(0).max_values(1); } - arg = arg.takes_value(true); let value_name = $crate::arg_impl! { @string $value_name }; if arg.get_id().is_empty() { arg = arg.id(value_name); } - arg.value_name(value_name).action($crate::ArgAction::Set) + arg + .value_name(value_name) + .action($crate::ArgAction::Set) + .takes_value(true) }) $($tail)* } diff --git a/src/parser/matches/arg_matches.rs b/src/parser/matches/arg_matches.rs index 63f352ae378..978c745ce4c 100644 --- a/src/parser/matches/arg_matches.rs +++ b/src/parser/matches/arg_matches.rs @@ -26,16 +26,16 @@ use crate::INTERNAL_ERROR_MSG; /// # Examples /// /// ```no_run -/// # use clap::{Command, Arg, ValueSource}; +/// # use clap::{Command, Arg, ValueSource, ArgAction}; /// let matches = Command::new("MyApp") /// .arg(Arg::new("out") /// .long("output") /// .required(true) -/// .takes_value(true) +/// .action(ArgAction::Set) /// .default_value("-")) /// .arg(Arg::new("cfg") /// .short('c') -/// .takes_value(true)) +/// .action(ArgAction::Set)) /// .get_matches(); // builds the instance of ArgMatches /// /// // to get information about the "cfg" argument we created, such as the value supplied we use @@ -92,11 +92,11 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, value_parser}; + /// # use clap::{Command, Arg, value_parser, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("port") /// .value_parser(value_parser!(usize)) - /// .takes_value(true) + /// .action(ArgAction::Set) /// .required(true)) /// .get_matches_from(vec!["myapp", "2020"]); /// @@ -136,7 +136,6 @@ impl ArgMatches { /// .action(ArgAction::Append) /// .value_parser(value_parser!(usize)) /// .short('p') - /// .takes_value(true) /// .required(true)) /// .get_matches_from(vec![ /// "myprog", "-p", "22", "-p", "80", "-p", "2020" @@ -222,11 +221,11 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, value_parser}; + /// # use clap::{Command, Arg, value_parser, ArgAction}; /// let mut m = Command::new("myprog") /// .arg(Arg::new("file") /// .required(true) - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "myprog", "file.txt", /// ]); @@ -265,7 +264,7 @@ impl ArgMatches { /// .action(ArgAction::Append) /// .multiple_values(true) /// .required(true) - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec![ /// "myprog", "file1.txt", "file2.txt", "file3.txt", "file4.txt", /// ]); @@ -296,10 +295,11 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myprog") /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .get_matches_from(vec![ /// "myprog", "-d" /// ]); @@ -318,10 +318,10 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let mut cmd = Command::new("myapp") /// .arg(Arg::new("output") - /// .takes_value(true)); + /// .action(ArgAction::Set)); /// /// let m = cmd /// .try_get_matches_from_mut(vec!["myapp", "something"]) @@ -409,10 +409,11 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{Command, Arg, ValueSource}; + /// # use clap::{Command, Arg, ValueSource, ArgAction}; /// let m = Command::new("myprog") /// .arg(Arg::new("debug") - /// .short('d')) + /// .short('d') + /// .action(ArgAction::SetTrue)) /// .get_matches_from(vec![ /// "myprog", "-d" /// ]); @@ -475,13 +476,14 @@ impl ArgMatches { /// in an `ArgMatches` struct for querying. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec!["myapp", "-f", "-o", "val"]); /// // ARGV indices: ^0 ^1 ^2 ^3 /// // clap indices: ^1 ^3 @@ -493,13 +495,14 @@ impl ArgMatches { /// Now notice, if we use one of the other styles of options: /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec!["myapp", "-f", "-o=val"]); /// // ARGV indices: ^0 ^1 ^2 /// // clap indices: ^1 ^3 @@ -512,17 +515,20 @@ impl ArgMatches { /// flags. Let's also throw in the final option style for good measure. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("flag2") - /// .short('F')) + /// .short('F') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("flag3") - /// .short('z')) + /// .short('z') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec!["myapp", "-fzF", "-oval"]); /// // ARGV indices: ^0 ^1 ^2 /// // clap indices: ^1,2,3 ^5 @@ -538,17 +544,20 @@ impl ArgMatches { /// One final combination of flags/options to see how they combine: /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("flag") - /// .short('f')) + /// .short('f') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("flag2") - /// .short('F')) + /// .short('F') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("flag3") - /// .short('z')) + /// .short('z') + /// .action(ArgAction::SetTrue)) /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true)) + /// .action(ArgAction::Set)) /// .get_matches_from(vec!["myapp", "-fzFoval"]); /// // ARGV indices: ^0 ^1 /// // clap indices: ^1,2,3^5 @@ -628,7 +637,7 @@ impl ArgMatches { /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .action(ArgAction::Append)) /// .arg(Arg::new("flag") /// .short('f') @@ -647,11 +656,11 @@ impl ArgMatches { /// index. /// /// ```rust - /// # use clap::{Command, Arg}; + /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') - /// .takes_value(true) + /// .action(ArgAction::Set) /// .multiple_values(true)) /// .get_matches_from(vec!["myapp", "-o=val1,val2,val3"]); /// // ARGV indices: ^0 ^1 @@ -813,7 +822,7 @@ impl ArgMatches { /// .subcommand(Command::new("test") /// .arg(Arg::new("opt") /// .long("option") - /// .takes_value(true))) + /// .action(ArgAction::Set))) /// .get_matches_from(vec![ /// "myprog", "-d", "test", "--option", "val" /// ]); @@ -1135,8 +1144,7 @@ pub(crate) struct SubCommand { /// let mut m = Command::new("myapp") /// .arg(Arg::new("output") /// .short('o') -/// .action(ArgAction::Append) -/// .takes_value(true)) +/// .action(ArgAction::Append)) /// .get_matches_from(vec!["myapp", "-o", "val1", "-o", "val2"]); /// /// let mut values = m.remove_many::("output") @@ -1192,8 +1200,7 @@ impl Default for Values2 { /// let m = Command::new("myapp") /// .arg(Arg::new("output") /// .short('o') -/// .action(ArgAction::Append) -/// .takes_value(true)) +/// .action(ArgAction::Append)) /// .get_matches_from(vec!["myapp", "-o", "val1", "-o", "val2"]); /// /// let mut values = m.get_many::("output") @@ -1351,12 +1358,12 @@ impl<'a> Default for GroupedValues<'a> { /// # Examples /// /// ```rust -/// # use clap::{Command, Arg}; +/// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("myapp") /// .arg(Arg::new("output") /// .short('o') /// .multiple_values(true) -/// .takes_value(true)) +/// .action(ArgAction::Set)) /// .get_matches_from(vec!["myapp", "-o", "val1", "val2"]); /// /// let mut indices = m.indices_of("output").unwrap(); @@ -1419,6 +1426,8 @@ fn unwrap_string(value: &AnyValue) -> &str { mod tests { use super::*; + use crate::ArgAction; + #[test] fn check_auto_traits() { static_assertions::assert_impl_all!(ArgMatches: Send, Sync, Unpin); @@ -1448,7 +1457,7 @@ mod tests { let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .required(true), ) @@ -1465,7 +1474,7 @@ mod tests { let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .value_parser(crate::builder::ValueParser::os_string()) .required(true), @@ -1483,7 +1492,7 @@ mod tests { let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .required(true), ) diff --git a/tests/builder/app_settings.rs b/tests/builder/app_settings.rs index 4ecafc9d093..496427d40b3 100644 --- a/tests/builder/app_settings.rs +++ b/tests/builder/app_settings.rs @@ -143,7 +143,8 @@ OPTIONS: Arg::new("info") .help("Provides more info") .short('i') - .long("info"), + .long("info") + .action(ArgAction::SetTrue), ); utils::assert_output( cmd, @@ -473,7 +474,7 @@ fn leading_hyphen_long() { fn leading_hyphen_opt() { let res = Command::new("leadhy") .allow_hyphen_values(true) - .arg(Arg::new("some").takes_value(true).long("opt")) + .arg(Arg::new("some").action(ArgAction::Set).long("opt")) .arg(Arg::new("other").short('o').action(ArgAction::SetTrue)) .try_get_matches_from(vec!["", "--opt", "--bar", "-o"]); assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind()); @@ -495,7 +496,7 @@ fn allow_negative_numbers() { let res = Command::new("negnum") .allow_negative_numbers(true) .arg(Arg::new("panum")) - .arg(Arg::new("onum").short('o').takes_value(true)) + .arg(Arg::new("onum").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["negnum", "-20", "-o", "-1.2"]); assert!(res.is_ok(), "Error: {:?}", res.unwrap_err().kind()); let m = res.unwrap(); @@ -514,7 +515,7 @@ fn allow_negative_numbers_fail() { let res = Command::new("negnum") .allow_negative_numbers(true) .arg(Arg::new("panum")) - .arg(Arg::new("onum").short('o').takes_value(true)) + .arg(Arg::new("onum").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["negnum", "--foo", "-o", "-1.2"]); assert!(res.is_err()); assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument) @@ -826,7 +827,7 @@ fn issue_1437_allow_hyphen_values_for_positional_arg() { Arg::new("pat") .allow_hyphen_values(true) .required(true) - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(["tmp", "-file"]) .unwrap(); @@ -1149,7 +1150,7 @@ fn aaos_opts_mult_req_delims() { .arg( arg!(--opt ... "some option") .number_of_values(1) - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .require_value_delimiter(true) .action(ArgAction::Append), diff --git a/tests/builder/arg_aliases.rs b/tests/builder/arg_aliases.rs index 893797c4a19..3e9f671569a 100644 --- a/tests/builder/arg_aliases.rs +++ b/tests/builder/arg_aliases.rs @@ -8,7 +8,7 @@ fn single_alias_of_option() { .arg( Arg::new("alias") .long("alias") - .takes_value(true) + .action(ArgAction::Set) .help("single alias") .alias("new-opt"), ) @@ -27,7 +27,7 @@ fn multiple_aliases_of_option() { let a = Command::new("multiple_aliases").arg( Arg::new("aliases") .long("aliases") - .takes_value(true) + .action(ArgAction::Set) .help("multiple aliases") .aliases(&["alias1", "alias2", "alias3"]), ); @@ -89,7 +89,7 @@ fn multiple_aliases_of_option() { fn get_aliases() { let a = Arg::new("aliases") .long("aliases") - .takes_value(true) + .action(ArgAction::Set) .help("multiple aliases") .aliases(&["alias1", "alias2", "alias3"]) .short_aliases(&['a', 'b', 'c']) @@ -170,7 +170,7 @@ fn alias_on_a_subcommand_option() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .alias("opt") .help("testing testing"), ), @@ -211,7 +211,7 @@ OPTIONS: Arg::new("opt") .long("opt") .short('o') - .takes_value(true) + .action(ArgAction::Set) .aliases(&["invisible", "als1", "more"]), ) .arg(arg!(-f - -flag).aliases(&["unseeable", "flg1", "anyway"])), @@ -242,7 +242,7 @@ OPTIONS: Arg::new("opt") .long("opt") .short('o') - .takes_value(true) + .action(ArgAction::Set) .alias("invisible") .visible_alias("visible"), ) @@ -250,6 +250,7 @@ OPTIONS: Arg::new("flg") .long("flag") .short('f') + .action(ArgAction::SetTrue) .visible_aliases(&["v_flg", "flag2", "flg3"]), ), ); diff --git a/tests/builder/arg_aliases_short.rs b/tests/builder/arg_aliases_short.rs index ac1085c5321..cc23b7d3750 100644 --- a/tests/builder/arg_aliases_short.rs +++ b/tests/builder/arg_aliases_short.rs @@ -8,7 +8,7 @@ fn single_short_alias_of_option() { .arg( Arg::new("alias") .long("alias") - .takes_value(true) + .action(ArgAction::Set) .help("single short alias") .short_alias('a'), ) @@ -27,7 +27,7 @@ fn multiple_short_aliases_of_option() { let a = Command::new("multiple_aliases").arg( Arg::new("aliases") .long("aliases") - .takes_value(true) + .action(ArgAction::Set) .help("multiple aliases") .short_aliases(&['1', '2', '3']), ); @@ -133,7 +133,7 @@ fn short_alias_on_a_subcommand_option() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .short_alias('o') .help("testing testing"), ), @@ -178,7 +178,7 @@ OPTIONS: Arg::new("opt") .long("opt") .short('o') - .takes_value(true) + .action(ArgAction::Set) .short_aliases(&['a', 'b', 'c']), ) .arg(arg!(-f - -flag).short_aliases(&['x', 'y', 'z'])), @@ -209,7 +209,7 @@ OPTIONS: Arg::new("opt") .long("opt") .short('o') - .takes_value(true) + .action(ArgAction::Set) .short_alias('i') .visible_short_alias('v'), ) @@ -217,6 +217,7 @@ OPTIONS: Arg::new("flg") .long("flag") .short('f') + .action(ArgAction::SetTrue) .visible_alias("flag1") .visible_short_aliases(&['a', 'b', '🦆']), ), diff --git a/tests/builder/arg_matcher_assertions.rs b/tests/builder/arg_matcher_assertions.rs index a8474ac4431..1af4af81569 100644 --- a/tests/builder/arg_matcher_assertions.rs +++ b/tests/builder/arg_matcher_assertions.rs @@ -19,7 +19,7 @@ fn arg_matches_if_present_wrong_arg() { #[should_panic = "Mismatch between definition and access of `o`. Unknown argument or group id. Make sure you are using the argument id and not the short or long flags"] fn arg_matches_value_of_wrong_arg() { let m = Command::new("test") - .arg(Arg::new("opt").short('o').takes_value(true)) + .arg(Arg::new("opt").short('o').action(ArgAction::Set)) .try_get_matches_from(&["test", "-o", "val"]) .unwrap(); diff --git a/tests/builder/conflicts.rs b/tests/builder/conflicts.rs index 4fe5f658810..a205bbb107b 100644 --- a/tests/builder/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -360,16 +360,19 @@ fn conflict_output_three_conflicting() { .arg( Arg::new("one") .long("one") + .action(ArgAction::SetTrue) .conflicts_with_all(&["two", "three"]), ) .arg( Arg::new("two") .long("two") + .action(ArgAction::SetTrue) .conflicts_with_all(&["one", "three"]), ) .arg( Arg::new("three") .long("three") + .action(ArgAction::SetTrue) .conflicts_with_all(&["one", "two"]), ); utils::assert_output( @@ -386,11 +389,13 @@ fn two_conflicting_arguments() { .arg( Arg::new("develop") .long("develop") + .action(ArgAction::SetTrue) .conflicts_with("production"), ) .arg( Arg::new("production") .long("production") + .action(ArgAction::SetTrue) .conflicts_with("develop"), ) .try_get_matches_from(vec!["", "--develop", "--production"]); @@ -411,16 +416,19 @@ fn three_conflicting_arguments() { .arg( Arg::new("one") .long("one") + .action(ArgAction::SetTrue) .conflicts_with_all(&["two", "three"]), ) .arg( Arg::new("two") .long("two") + .action(ArgAction::SetTrue) .conflicts_with_all(&["one", "three"]), ) .arg( Arg::new("three") .long("three") + .action(ArgAction::SetTrue) .conflicts_with_all(&["one", "two"]), ) .try_get_matches_from(vec!["", "--one", "--two", "--three"]); @@ -596,8 +604,13 @@ fn group_conflicts_with_default_arg() { #[test] fn exclusive_with_required() { let cmd = Command::new("bug") - .arg(Arg::new("test").long("test").exclusive(true)) - .arg(Arg::new("input").takes_value(true).required(true)); + .arg( + Arg::new("test") + .long("test") + .action(ArgAction::SetTrue) + .exclusive(true), + ) + .arg(Arg::new("input").action(ArgAction::Set).required(true)); cmd.clone() .try_get_matches_from(["bug", "--test", "required"]) diff --git a/tests/builder/default_missing_vals.rs b/tests/builder/default_missing_vals.rs index 325021ee6ea..7f3b6c66e37 100644 --- a/tests/builder/default_missing_vals.rs +++ b/tests/builder/default_missing_vals.rs @@ -1,4 +1,4 @@ -use clap::{arg, Arg, Command}; +use clap::{arg, Arg, ArgAction, Command}; #[test] fn opt_missing() { @@ -149,7 +149,7 @@ fn default_missing_value_flag_value() { let cmd = Command::new("test").arg( Arg::new("flag") .long("flag") - .takes_value(true) + .action(ArgAction::Set) .default_value("false") .default_missing_value("true"), ); @@ -277,7 +277,7 @@ fn valid_index() { .require_equals(true) .default_missing_value("always"), ) - .arg(Arg::new("sync").long("sync")) + .arg(Arg::new("sync").long("sync").action(ArgAction::SetTrue)) .try_get_matches_from(vec!["df", "--color", "--sync"]) .unwrap(); assert!(m.contains_id("color")); diff --git a/tests/builder/default_vals.rs b/tests/builder/default_vals.rs index 9709a061147..fc3ac69072e 100644 --- a/tests/builder/default_vals.rs +++ b/tests/builder/default_vals.rs @@ -2,7 +2,7 @@ use std::ffi::OsStr; use std::ffi::OsString; use super::utils; -use clap::{arg, error::ErrorKind, value_parser, Arg, Command}; +use clap::{arg, error::ErrorKind, value_parser, Arg, ArgAction, Command}; #[test] fn opts() { @@ -606,7 +606,7 @@ fn default_value_ifs_os() { Arg::new("flag") .long("flag") .value_parser(value_parser!(OsString)) - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("other") @@ -638,19 +638,19 @@ fn conditional_reqs_pass() { let m = Command::new("Test cmd") .arg( Arg::new("target") - .takes_value(true) + .action(ArgAction::Set) .default_value("file") .long("target"), ) .arg( Arg::new("input") - .takes_value(true) + .action(ArgAction::Set) .required(true) .long("input"), ) .arg( Arg::new("output") - .takes_value(true) + .action(ArgAction::Set) .required_if_eq("target", "file") .long("output"), ) @@ -712,7 +712,7 @@ fn default_vals_donnot_show_in_smart_usage() { .arg( Arg::new("foo") .long("config") - .takes_value(true) + .action(ArgAction::Set) .default_value("bar"), ) .arg(Arg::new("input").required(true)); @@ -738,7 +738,7 @@ fn issue_1050_num_vals_and_defaults() { .arg( Arg::new("exit-code") .long("exit-code") - .takes_value(true) + .action(ArgAction::Set) .number_of_values(1) .default_value("0"), ) diff --git a/tests/builder/delimiters.rs b/tests/builder/delimiters.rs index 5781494814e..78f416bfc2d 100644 --- a/tests/builder/delimiters.rs +++ b/tests/builder/delimiters.rs @@ -1,9 +1,9 @@ -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; #[test] fn opt_default_no_delim() { let m = Command::new("no_delim") - .arg(Arg::new("option").long("option").takes_value(true)) + .arg(Arg::new("option").long("option").action(ArgAction::Set)) .try_get_matches_from(vec!["", "--option", "val1,val2,val3"]); assert!(m.is_ok(), "{}", m.unwrap_err()); @@ -19,7 +19,7 @@ fn opt_default_no_delim() { #[test] fn opt_eq_no_delim() { let m = Command::new("no_delim") - .arg(Arg::new("option").long("option").takes_value(true)) + .arg(Arg::new("option").long("option").action(ArgAction::Set)) .try_get_matches_from(vec!["", "--option=val1,val2,val3"]); assert!(m.is_ok(), "{}", m.unwrap_err()); @@ -35,7 +35,7 @@ fn opt_eq_no_delim() { #[test] fn opt_s_eq_no_delim() { let m = Command::new("no_delim") - .arg(Arg::new("option").short('o').takes_value(true)) + .arg(Arg::new("option").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["", "-o=val1,val2,val3"]); assert!(m.is_ok(), "{:?}", m.unwrap_err()); @@ -51,7 +51,7 @@ fn opt_s_eq_no_delim() { #[test] fn opt_s_default_no_delim() { let m = Command::new("no_delim") - .arg(Arg::new("option").short('o').takes_value(true)) + .arg(Arg::new("option").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["", "-o", "val1,val2,val3"]); assert!(m.is_ok(), "{:?}", m.unwrap_err()); @@ -67,7 +67,7 @@ fn opt_s_default_no_delim() { #[test] fn opt_s_no_space_no_delim() { let m = Command::new("no_delim") - .arg(Arg::new("option").short('o').takes_value(true)) + .arg(Arg::new("option").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["", "-o", "val1,val2,val3"]); assert!(m.is_ok(), "{}", m.unwrap_err()); @@ -86,7 +86,7 @@ fn opt_s_no_space_mult_no_delim() { .arg( Arg::new("option") .short('o') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec!["", "-o", "val1,val2,val3"]); @@ -107,7 +107,7 @@ fn opt_eq_mult_def_delim() { .arg( Arg::new("option") .long("opt") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .use_value_delimiter(true), ) diff --git a/tests/builder/derive_order.rs b/tests/builder/derive_order.rs index ccc1cd3fef5..45ee9499990 100644 --- a/tests/builder/derive_order.rs +++ b/tests/builder/derive_order.rs @@ -2,7 +2,7 @@ use super::utils; use std::str; -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; #[test] fn no_derive_order() { @@ -24,15 +24,21 @@ OPTIONS: .version("1.2") .next_display_order(None) .args(&[ - Arg::new("flag_b").long("flag_b").help("first flag"), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), - Arg::new("flag_a").long("flag_a").help("second flag"), + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ]); @@ -56,15 +62,21 @@ OPTIONS: "; let cmd = Command::new("test").version("1.2").args(&[ - Arg::new("flag_b").long("flag_b").help("first flag"), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), - Arg::new("flag_a").long("flag_a").help("second flag"), + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ]); @@ -90,19 +102,29 @@ OPTIONS: let cmd = Command::new("test") .version("1.2") .next_display_order(10000) - .arg(Arg::new("flag_a").long("flag_a").help("second flag")) + .arg( + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), + ) .arg( Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ) .next_display_order(10) - .arg(Arg::new("flag_b").long("flag_b").help("first flag")) + .arg( + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), + ) .arg( Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), ); @@ -128,18 +150,28 @@ OPTIONS: let cmd = Command::new("test") .version("1.2") .next_display_order(None) - .arg(Arg::new("flag_a").long("flag_a").help("first flag")) + .arg( + Arg::new("flag_a") + .long("flag_a") + .help("first flag") + .action(ArgAction::SetTrue), + ) .arg( Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), ) - .arg(Arg::new("flag_b").long("flag_b").help("second flag")) + .arg( + Arg::new("flag_b") + .long("flag_b") + .help("second flag") + .action(ArgAction::SetTrue), + ) .arg( Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ); @@ -164,15 +196,21 @@ OPTIONS: let cmd = Command::new("test").subcommand( Command::new("sub").version("1.2").args(&[ - Arg::new("flag_b").long("flag_b").help("first flag"), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), - Arg::new("flag_a").long("flag_a").help("second flag"), + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ]), ); @@ -198,18 +236,22 @@ OPTIONS: let cmd = Command::new("test").subcommand( Command::new("sub").version("1.2").args(&[ - Arg::new("flag_b").long("flag_b").help("first flag"), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), Arg::new("option_b") .long("option_b") - .takes_value(true) + .action(ArgAction::Set) .help("first option"), Arg::new("flag_a") .long("flag_a") .help("second flag") - .display_order(0), + .display_order(0) + .action(ArgAction::SetTrue), Arg::new("option_a") .long("option_a") - .takes_value(true) + .action(ArgAction::Set) .help("second option"), ]), ); @@ -240,9 +282,16 @@ OPTIONS: Arg::new("help") .long("help") .short('h') - .help("Print help message"), - Arg::new("flag_b").long("flag_b").help("first flag"), - Arg::new("flag_a").long("flag_a").help("second flag"), + .help("Print help message") + .action(ArgAction::Help), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), ]); utils::assert_output(cmd, "test --help", PREFER_USER_HELP_DERIVE_ORDER, false); @@ -267,9 +316,16 @@ OPTIONS: Arg::new("help") .long("help") .short('h') - .help("Print help message"), - Arg::new("flag_b").long("flag_b").help("first flag"), - Arg::new("flag_a").long("flag_a").help("second flag"), + .help("Print help message") + .action(ArgAction::Help), + Arg::new("flag_b") + .long("flag_b") + .help("first flag") + .action(ArgAction::SetTrue), + Arg::new("flag_a") + .long("flag_a") + .help("second flag") + .action(ArgAction::SetTrue), ]), ); @@ -304,10 +360,10 @@ SUBCOMMANDS: .subcommands(vec![ Command::new("b1") .about("blah b1") - .arg(Arg::new("test").short('t')), + .arg(Arg::new("test").short('t').action(ArgAction::SetTrue)), Command::new("a1") .about("blah a1") - .arg(Arg::new("roster").short('r')), + .arg(Arg::new("roster").short('r').action(ArgAction::SetTrue)), ]); utils::assert_output( @@ -338,10 +394,10 @@ SUBCOMMANDS: let app_subcmd_decl_order = Command::new("test").version("1").subcommands(vec![ Command::new("b1") .about("blah b1") - .arg(Arg::new("test").short('t')), + .arg(Arg::new("test").short('t').action(ArgAction::SetTrue)), Command::new("a1") .about("blah a1") - .arg(Arg::new("roster").short('r')), + .arg(Arg::new("roster").short('r').action(ArgAction::SetTrue)), ]); utils::assert_output( diff --git a/tests/builder/double_require.rs b/tests/builder/double_require.rs index 13470cff6c1..6879be0dac1 100644 --- a/tests/builder/double_require.rs +++ b/tests/builder/double_require.rs @@ -1,4 +1,4 @@ -use clap::{error::ErrorKind, Arg, Command}; +use clap::{error::ErrorKind, Arg, ArgAction, Command}; static HELP: &str = "prog @@ -35,18 +35,21 @@ fn cmd() -> Command<'static> { .arg( Arg::new("a") .short('a') + .action(ArgAction::SetTrue) .required_unless_present_any(&["b", "c"]) .conflicts_with_all(&["b", "c"]), ) .arg( Arg::new("b") .short('b') + .action(ArgAction::SetTrue) .required_unless_present("a") .requires("c"), ) .arg( Arg::new("c") .short('c') + .action(ArgAction::SetTrue) .required_unless_present("a") .requires("b"), ) diff --git a/tests/builder/empty_values.rs b/tests/builder/empty_values.rs index 652177c8edd..da0596ab10b 100644 --- a/tests/builder/empty_values.rs +++ b/tests/builder/empty_values.rs @@ -1,11 +1,11 @@ use super::utils; -use clap::{error::ErrorKind, Arg, Command}; +use clap::{error::ErrorKind, Arg, ArgAction, Command}; #[test] fn empty_values() { let m = Command::new("config") - .arg(Arg::new("config").long("config").takes_value(true)) + .arg(Arg::new("config").long("config").action(ArgAction::Set)) .try_get_matches_from(&["config", "--config", ""]) .unwrap(); assert_eq!(m.get_one::("config").map(|v| v.as_str()), Some("")); @@ -14,13 +14,13 @@ fn empty_values() { #[test] fn empty_values_with_equals() { let m = Command::new("config") - .arg(Arg::new("config").long("config").takes_value(true)) + .arg(Arg::new("config").long("config").action(ArgAction::Set)) .try_get_matches_from(&["config", "--config="]) .unwrap(); assert_eq!(m.get_one::("config").map(|v| v.as_str()), Some("")); let m = Command::new("config") - .arg(Arg::new("config").short('c').takes_value(true)) + .arg(Arg::new("config").short('c').action(ArgAction::Set)) .try_get_matches_from(&["config", "-c="]) .unwrap(); assert_eq!(m.get_one::("config").map(|v| v.as_str()), Some("")) @@ -32,7 +32,7 @@ fn no_empty_values() { .arg( Arg::new("config") .long("config") - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "--config", ""]); @@ -43,7 +43,7 @@ fn no_empty_values() { .arg( Arg::new("config") .short('c') - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "-c", ""]); @@ -57,7 +57,7 @@ fn no_empty_values_with_equals() { .arg( Arg::new("config") .long("config") - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "--config="]); @@ -68,7 +68,7 @@ fn no_empty_values_with_equals() { .arg( Arg::new("config") .short('c') - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "-c="]); @@ -82,7 +82,7 @@ fn no_empty_values_without_equals() { .arg( Arg::new("config") .long("config") - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "--config"]); @@ -93,7 +93,7 @@ fn no_empty_values_without_equals() { .arg( Arg::new("config") .short('c') - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()), ) .try_get_matches_from(&["config", "-c"]); @@ -106,7 +106,7 @@ fn no_empty_values_without_equals_but_requires_equals() { let cmd = Command::new("config").arg( Arg::new("config") .long("config") - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::builder::NonEmptyStringValueParser::new()) .require_equals(true), ); diff --git a/tests/builder/env.rs b/tests/builder/env.rs index 98a7107d628..71184d9259b 100644 --- a/tests/builder/env.rs +++ b/tests/builder/env.rs @@ -10,7 +10,11 @@ fn env() { env::set_var("CLP_TEST_ENV", "env"); let r = Command::new("df") - .arg(arg!([arg] "some opt").env("CLP_TEST_ENV").takes_value(true)) + .arg( + arg!([arg] "some opt") + .env("CLP_TEST_ENV") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![""]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -66,7 +70,7 @@ fn env_os() { .arg( arg!([arg] "some opt") .env_os(OsStr::new("CLP_TEST_ENV_OS")) - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(vec![""]); @@ -89,7 +93,7 @@ fn no_env() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_NONE") - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(vec![""]); @@ -123,7 +127,7 @@ fn with_default() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_WD") - .takes_value(true) + .action(ArgAction::Set) .default_value("default"), ) .try_get_matches_from(vec![""]); @@ -145,7 +149,7 @@ fn opt_user_override() { .arg( arg!(--arg [FILE] "some arg") .env("CLP_TEST_ENV_OR") - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(vec!["", "--arg", "opt"]); @@ -174,7 +178,7 @@ fn positionals() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_P") - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(vec![""]); @@ -195,7 +199,7 @@ fn positionals_user_override() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_POR") - .takes_value(true), + .action(ArgAction::Set), ) .try_get_matches_from(vec!["", "opt"]); @@ -224,7 +228,7 @@ fn multiple_one() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MO") - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .multiple_values(true), ) @@ -250,7 +254,7 @@ fn multiple_three() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI1") - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .multiple_values(true), ) @@ -276,7 +280,7 @@ fn multiple_no_delimiter() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI2") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec![""]); @@ -301,7 +305,7 @@ fn possible_value() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_PV") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["env"]), ) .try_get_matches_from(vec![""]); @@ -323,7 +327,7 @@ fn not_possible_value() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_NPV") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["never"]), ) .try_get_matches_from(vec![""]); @@ -339,7 +343,7 @@ fn value_parser() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_VDOR") - .takes_value(true) + .action(ArgAction::Set) .value_parser(|s: &str| -> Result { if s == "env" { Ok(s.to_owned()) @@ -367,7 +371,7 @@ fn value_parser_output() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_VO") - .takes_value(true) + .action(ArgAction::Set) .value_parser(clap::value_parser!(i32)), ) .try_get_matches_from(vec![""]) @@ -384,7 +388,7 @@ fn value_parser_invalid() { .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_IV") - .takes_value(true) + .action(ArgAction::Set) .value_parser(|s: &str| -> Result { if s != "env" { Ok(s.to_owned()) diff --git a/tests/builder/error.rs b/tests/builder/error.rs index 61f8dcf2385..464e6baee54 100644 --- a/tests/builder/error.rs +++ b/tests/builder/error.rs @@ -2,6 +2,7 @@ use super::utils; use clap::{arg, error::ErrorKind, value_parser, Arg, Command, Error}; +#[track_caller] fn assert_error(err: Error, expected_kind: ErrorKind, expected_output: &str, stderr: bool) { let actual_output = err.to_string(); assert_eq!( @@ -30,6 +31,7 @@ For more information try --help .short('a') .long("all") .required(true) + .action(clap::ArgAction::SetTrue) .help("Also do versioning for private crates (will not be published)"), ) .arg( diff --git a/tests/builder/flag_subcommands.rs b/tests/builder/flag_subcommands.rs index 5b733c6b6c7..0b53597dd84 100644 --- a/tests/builder/flag_subcommands.rs +++ b/tests/builder/flag_subcommands.rs @@ -234,7 +234,7 @@ fn flag_subcommand_short_after_long_arg() { .short_flag('S') .arg(Arg::new("clean").short('c').action(ArgAction::SetTrue)), ) - .arg(Arg::new("arg").long("arg").takes_value(true)) + .arg(Arg::new("arg").long("arg").action(ArgAction::Set)) .try_get_matches_from(vec!["pacman", "--arg", "foo", "-Sc"]) .unwrap(); let subm = m.subcommand_matches("sync"); @@ -525,7 +525,7 @@ fn flag_subcommand_long_short_normal_usage_string() { .long("search") .help("search locally installed packages for matching strings") .conflicts_with("info") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg( @@ -534,7 +534,7 @@ fn flag_subcommand_long_short_normal_usage_string() { .short('i') .conflicts_with("search") .help("view package information") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ), ); @@ -573,7 +573,7 @@ fn flag_subcommand_long_normal_usage_string() { .long("search") .help("search locally installed packages for matching strings") .conflicts_with("info") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg( @@ -582,7 +582,7 @@ fn flag_subcommand_long_normal_usage_string() { .short('i') .conflicts_with("search") .help("view package information") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ), ); @@ -626,7 +626,7 @@ fn flag_subcommand_short_normal_usage_string() { .long("search") .help("search locally installed packages for matching strings") .conflicts_with("info") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg( @@ -635,7 +635,7 @@ fn flag_subcommand_short_normal_usage_string() { .short('i') .conflicts_with("search") .help("view package information") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ), ); diff --git a/tests/builder/flags.rs b/tests/builder/flags.rs index 8715b1b50a9..43b5904acf3 100644 --- a/tests/builder/flags.rs +++ b/tests/builder/flags.rs @@ -95,7 +95,11 @@ fn flag_using_long_with_literals() { use clap::error::ErrorKind; let m = Command::new("flag") - .arg(Arg::new("rainbow").long("rainbow")) + .arg( + Arg::new("rainbow") + .long("rainbow") + .action(ArgAction::SetTrue), + ) .try_get_matches_from(vec!["", "--rainbow=false"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::TooManyValues); @@ -184,7 +188,7 @@ USAGE: For more information try --help "; - let cmd = Command::new("test").arg(Arg::new("arg").takes_value(true).required(true)); + let cmd = Command::new("test").arg(Arg::new("arg").action(ArgAction::Set).required(true)); utils::assert_output(cmd, "test -----", MULTIPLE_DASHES, true); } diff --git a/tests/builder/global_args.rs b/tests/builder/global_args.rs index 2f9833bb911..aece1dfd37c 100644 --- a/tests/builder/global_args.rs +++ b/tests/builder/global_args.rs @@ -8,7 +8,7 @@ fn issue_1076() { .long("global-arg") .help("Specifies something needed by the subcommands") .global(true) - .takes_value(true) + .action(ArgAction::Set) .default_value("default_value"), ) .arg( @@ -16,7 +16,7 @@ fn issue_1076() { .long("global-flag") .help("Specifies something needed by the subcommands") .global(true) - .takes_value(true), + .action(ArgAction::Set), ) .subcommand(Command::new("outer").subcommand(Command::new("inner"))); let _ = cmd.try_get_matches_from_mut(vec!["myprog"]); @@ -29,7 +29,12 @@ fn propagate_global_arg_in_subcommand_to_subsubcommand_1385() { let m1 = Command::new("foo") .subcommand( Command::new("sub1") - .arg(Arg::new("arg1").long("arg1").takes_value(true).global(true)) + .arg( + Arg::new("arg1") + .long("arg1") + .action(ArgAction::Set) + .global(true), + ) .subcommand(Command::new("sub1a")), ) .try_get_matches_from(&["foo", "sub1", "--arg1", "v1", "sub1a"]) @@ -134,7 +139,7 @@ fn global_overrides_default() { Arg::new("name") .long("name") .global(true) - .takes_value(true) + .action(ArgAction::Set) .default_value("from_default"), ) .subcommand(Command::new("sub")); @@ -174,7 +179,7 @@ fn global_overrides_env() { Arg::new("name") .long("name") .global(true) - .takes_value(true) + .action(ArgAction::Set) .env("GLOBAL_OVERRIDES_ENV"), ) .subcommand(Command::new("sub")); diff --git a/tests/builder/grouped_values.rs b/tests/builder/grouped_values.rs index f7db11873aa..d740a2ff6bc 100644 --- a/tests/builder/grouped_values.rs +++ b/tests/builder/grouped_values.rs @@ -8,7 +8,7 @@ fn grouped_value_works() { .arg( Arg::new("option") .long("option") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) @@ -35,12 +35,12 @@ fn grouped_value_works() { #[test] fn issue_1026() { let m = Command::new("cli") - .arg(Arg::new("server").short('s').takes_value(true)) - .arg(Arg::new("user").short('u').takes_value(true)) + .arg(Arg::new("server").short('s').action(ArgAction::Set)) + .arg(Arg::new("user").short('u').action(ArgAction::Set)) .arg( Arg::new("target") .long("target") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) @@ -67,7 +67,7 @@ fn grouped_value_long_flag_delimiter() { .arg( Arg::new("option") .long("option") - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .multiple_values(true) .action(ArgAction::Append), @@ -97,7 +97,7 @@ fn grouped_value_short_flag_delimiter() { .arg( Arg::new("option") .short('o') - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .multiple_values(true) .action(ArgAction::Append), @@ -117,7 +117,7 @@ fn grouped_value_positional_arg() { .arg( Arg::new("pos") .help("multiple positionals") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec![ @@ -138,7 +138,7 @@ fn grouped_value_multiple_positional_arg() { .arg( Arg::new("pos2") .help("multiple positionals") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec![ @@ -159,7 +159,7 @@ fn grouped_value_multiple_positional_arg_last_multiple() { .arg( Arg::new("pos2") .help("multiple positionals") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true), ) @@ -182,7 +182,7 @@ fn grouped_interleaved_positional_values() { clap::Arg::new("flag") .short('f') .long("flag") - .takes_value(true) + .action(ArgAction::Set) .action(ArgAction::Append), ); @@ -205,7 +205,7 @@ fn grouped_interleaved_positional_occurrences() { clap::Arg::new("flag") .short('f') .long("flag") - .takes_value(true) + .action(ArgAction::Set) .action(ArgAction::Append), ); diff --git a/tests/builder/groups.rs b/tests/builder/groups.rs index a54c741fbe7..c009ab09056 100644 --- a/tests/builder/groups.rs +++ b/tests/builder/groups.rs @@ -283,8 +283,18 @@ OPTIONS: #[test] fn group_acts_like_arg() { let result = Command::new("prog") - .arg(Arg::new("debug").long("debug").group("mode")) - .arg(Arg::new("verbose").long("verbose").group("mode")) + .arg( + Arg::new("debug") + .long("debug") + .group("mode") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("verbose") + .long("verbose") + .group("mode") + .action(ArgAction::SetTrue), + ) .try_get_matches_from(vec!["prog", "--debug"]); assert!(result.is_ok(), "{}", result.unwrap_err()); @@ -298,8 +308,8 @@ fn issue_1794() { let cmd = clap::Command::new("hello") .bin_name("deno") .arg(Arg::new("option1").long("option1").takes_value(false).action(ArgAction::SetTrue)) - .arg(Arg::new("pos1").takes_value(true)) - .arg(Arg::new("pos2").takes_value(true)) + .arg(Arg::new("pos1").action(ArgAction::Set)) + .arg(Arg::new("pos2").action(ArgAction::Set)) .group( ArgGroup::new("arg1") .args(&["pos1", "option1"]) diff --git a/tests/builder/help.rs b/tests/builder/help.rs index e00de1c3fca..3888a67e80d 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -171,7 +171,7 @@ OPTIONS: .arg( Arg::new("pass through args") .help("Any arguments you wish to pass to the being profiled.") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true) .value_name("ARGS"), @@ -506,7 +506,7 @@ OPTIONS: .arg( Arg::new("possible_values") .long("possible-values") - .takes_value(true) + .action(ArgAction::Set) .value_parser([ PossibleValue::new("short_name") .help("Long enough help message, barely warrant wrapping"), @@ -516,7 +516,7 @@ OPTIONS: .arg( Arg::new("possible_values_with_new_line") .long("possible-values-with-new-line") - .takes_value(true) + .action(ArgAction::Set) .value_parser([ PossibleValue::new("long enough name to trigger new line").help( "Really long enough help message to clearly warrant wrapping believe me", @@ -527,7 +527,7 @@ OPTIONS: .arg( Arg::new("possible_values_without_new_line") .long("possible-values-without-new-line") - .takes_value(true) + .action(ArgAction::Set) .value_parser([ PossibleValue::new("name").help("Short enough help message with no wrapping"), PossibleValue::new("second").help("short help"), @@ -593,7 +593,7 @@ OPTIONS: iced coffee and iced tea. Many cafés also serve some type of \ food, such as light snacks, muffins, or pastries.", ) - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", ISSUE_626_CUTOFF, false); } @@ -621,7 +621,7 @@ fn hide_possible_vals() { .value_name("VAL") .value_parser(["fast", "slow"]) .help("Some vals") - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("cafe") @@ -631,7 +631,7 @@ fn hide_possible_vals() { .hide_possible_values(true) .value_parser(["fast", "slow"]) .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false); } @@ -651,7 +651,7 @@ fn hide_single_possible_val() { PossibleValue::new("secret speed").hide(true), ]) .help("Some vals") - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("cafe") @@ -659,7 +659,7 @@ fn hide_single_possible_val() { .long("cafe") .value_name("FILE") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false); } @@ -701,7 +701,7 @@ OPTIONS: PossibleValue::new("secret speed").hide(true), ]) .help("Some vals") - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("cafe") @@ -709,7 +709,7 @@ OPTIONS: .long("cafe") .value_name("FILE") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(app, "ctest --help", POS_VALS_HELP, false); } @@ -748,7 +748,7 @@ OPTIONS: .help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \ d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \ Le café est souvent une contribution majeure aux exportations des régions productrices.") - .takes_value(true)); + .action(ArgAction::Set)); utils::assert_output(cmd, "ctest --help", ISSUE_626_PANIC, false); } @@ -765,7 +765,7 @@ fn issue_626_variable_panic() { .help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \ d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \ Le café est souvent une contribution majeure aux exportations des régions productrices.") - .takes_value(true)) + .action(ArgAction::Set)) .try_get_matches_from(vec!["ctest", "--help"]); } } @@ -884,6 +884,7 @@ fn old_newline_chars() { let cmd = Command::new("ctest").version("0.1").arg( Arg::new("mode") .short('m') + .action(ArgAction::SetTrue) .help("Some help with some wrapping\n(Defaults to something)"), ); utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false); @@ -894,6 +895,7 @@ fn old_newline_variables() { let cmd = Command::new("ctest").version("0.1").arg( Arg::new("mode") .short('m') + .action(ArgAction::SetTrue) .help("Some help with some wrapping{n}(Defaults to something)"), ); utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false); @@ -925,7 +927,7 @@ OPTIONS: images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]") .long("filter") .value_parser(filter_values) - .takes_value(true)); + .action(ArgAction::Set)); utils::assert_output(app1, "ctest --help", ISSUE_688, false); let app2 = Command::new("ctest") @@ -936,7 +938,7 @@ OPTIONS: images. The default is Linear (Bilinear).") .long("filter") .value_parser(filter_values) - .takes_value(true)); + .action(ArgAction::Set)); utils::assert_output(app2, "ctest --help", ISSUE_688, false); let app3 = Command::new("ctest") @@ -946,7 +948,7 @@ OPTIONS: .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]") .long("filter") - .takes_value(true)); + .action(ArgAction::Set)); utils::assert_output(app3, "ctest --help", ISSUE_688, false); } @@ -978,7 +980,7 @@ OPTIONS: .arg(Arg::new("arg1").help("some option")) .arg( Arg::new("arg2") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .help("some option"), ) @@ -987,14 +989,14 @@ OPTIONS: .help("some option") .short('s') .long("some") - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("other") .help("some other option") .short('o') .long("other") - .takes_value(true), + .action(ArgAction::Set), ) .arg( Arg::new("label") @@ -1002,7 +1004,7 @@ OPTIONS: .short('l') .long("label") .multiple_values(true) - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "myapp --help", ISSUE_702, false); } @@ -1063,7 +1065,7 @@ OPTIONS: .help("tests options") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .number_of_values(1), ) @@ -1072,7 +1074,7 @@ OPTIONS: .help("tests options") .short('O') .long("opt") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", ISSUE_760, false); } @@ -1084,7 +1086,7 @@ fn issue_1571() { .long("package") .short('p') .number_of_values(1) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ); utils::assert_output( @@ -1363,7 +1365,7 @@ OPTIONS: --help Print help information "; - let cmd = Command::new("conflict").arg(Arg::new("home").short('h')); + let cmd = Command::new("conflict").arg(Arg::new("home").short('h').action(ArgAction::SetTrue)); utils::assert_output(cmd, "conflict --help", HELP_CONFLICT, false); } @@ -1401,7 +1403,7 @@ OPTIONS: .arg(Arg::new("CORPUS").help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true) .help("some"), @@ -1432,7 +1434,7 @@ OPTIONS: .arg(Arg::new("CORPUS").help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true) .required(true) @@ -1470,7 +1472,7 @@ SUBCOMMANDS: .arg(Arg::new("CORPUS").help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true) .required(true) @@ -1509,7 +1511,7 @@ SUBCOMMANDS: .arg(Arg::new("CORPUS").help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true) .help("some"), @@ -1661,7 +1663,7 @@ OPTIONS: arg!(-f --fake "some help") .required(true) .value_names(&["some", "val"]) - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .require_value_delimiter(true) .value_delimiter(':'), @@ -1697,7 +1699,7 @@ NETWORKING: arg!(-f --fake "some help") .required(true) .value_names(&["some", "val"]) - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .require_value_delimiter(true) .value_delimiter(':'), @@ -1707,9 +1709,10 @@ NETWORKING: Arg::new("no-proxy") .short('n') .long("no-proxy") + .action(ArgAction::SetTrue) .help("Do not use system proxy settings"), ) - .args(&[Arg::new("port").long("port")]); + .args(&[Arg::new("port").long("port").action(ArgAction::SetTrue)]); utils::assert_output(cmd, "test --help", CUSTOM_HELP_SECTION, false); } @@ -1749,7 +1752,7 @@ fn multiple_custom_help_headers() { arg!(-f --fake "some help") .required(true) .value_names(&["some", "val"]) - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .require_value_delimiter(true) .value_delimiter(':'), @@ -1759,6 +1762,7 @@ fn multiple_custom_help_headers() { Arg::new("no-proxy") .short('n') .long("no-proxy") + .action(ArgAction::SetTrue) .help("Do not use system proxy settings"), ) .next_help_heading(Some("SPECIAL")) @@ -1779,6 +1783,7 @@ fn multiple_custom_help_headers() { Arg::new("server-addr") .short('a') .long("server-addr") + .action(ArgAction::SetTrue) .help("Set server address") .help_heading(Some("NETWORKING")), ) @@ -1789,7 +1794,7 @@ fn multiple_custom_help_headers() { .value_name("SPEED") .value_parser(["fast", "slow"]) .help("How fast?") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "test --help", MULTIPLE_CUSTOM_HELP_SECTIONS, false); @@ -1911,7 +1916,7 @@ OPTIONS: "; let cmd = Command::new("demo") - .arg(Arg::new("foo").short('f')) + .arg(Arg::new("foo").short('f').action(ArgAction::SetTrue)) .arg( Arg::new("baz") .short('z') @@ -1921,7 +1926,7 @@ OPTIONS: .arg( Arg::new("files") .value_name("FILES") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ); @@ -2069,12 +2074,17 @@ OPTIONS: Print help information "; - let cmd = Command::new("prog").arg(Arg::new("cfg").long("config").long_help( - "The config file used by the myprog must be in JSON format + let cmd = Command::new("prog").arg( + Arg::new("cfg") + .long("config") + .action(ArgAction::SetTrue) + .long_help( + "The config file used by the myprog must be in JSON format with only valid keys and may not contain other nonsense that cannot be read by this program. Obviously I'm going on and on, so I'll stop now.", - )); + ), + ); utils::assert_output(cmd, "prog --help", ISSUE_1642, false); } @@ -2244,13 +2254,17 @@ OPTIONS: "; let cmd = Command::new("order").args(&[ - Arg::new("a").short('a'), - Arg::new("B").short('B'), - Arg::new("b").short('b'), - Arg::new("save").short('s'), - Arg::new("select_file").long("select_file"), - Arg::new("select_folder").long("select_folder"), - Arg::new("x").short('x'), + Arg::new("a").short('a').action(ArgAction::SetTrue), + Arg::new("B").short('B').action(ArgAction::SetTrue), + Arg::new("b").short('b').action(ArgAction::SetTrue), + Arg::new("save").short('s').action(ArgAction::SetTrue), + Arg::new("select_file") + .long("select_file") + .action(ArgAction::SetTrue), + Arg::new("select_folder") + .long("select_folder") + .action(ArgAction::SetTrue), + Arg::new("x").short('x').action(ArgAction::SetTrue), ]); utils::assert_output(cmd, "order --help", OPTION_USAGE_ORDER, false); @@ -2304,13 +2318,13 @@ OPTIONS: let cmd = clap::Command::new("hello") .bin_name("deno") .arg(Arg::new("option1").long("option1").takes_value(false)) - .arg(Arg::new("pos1").takes_value(true)) + .arg(Arg::new("pos1").action(ArgAction::Set)) .group( ArgGroup::new("arg1") .args(&["pos1", "option1"]) .required(true), ) - .arg(Arg::new("pos2").takes_value(true)); + .arg(Arg::new("pos2").action(ArgAction::Set)); utils::assert_output(cmd, "deno --help", USAGE_WITH_GROUP, false); } @@ -2442,7 +2456,7 @@ fn missing_positional_final_multiple() { .allow_missing_positional(true) .arg(Arg::new("foo")) .arg(Arg::new("bar")) - .arg(Arg::new("baz").takes_value(true).multiple_values(true)); + .arg(Arg::new("baz").action(ArgAction::Set).multiple_values(true)); utils::assert_output( cmd, "test --help", @@ -2468,7 +2482,7 @@ fn positional_multiple_values_is_dotted() { let cmd = Command::new("test").arg( Arg::new("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ); utils::assert_output( @@ -2491,7 +2505,7 @@ OPTIONS: let cmd = Command::new("test").arg( Arg::new("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .value_name("BAR") .multiple_values(true), ); @@ -2518,7 +2532,7 @@ fn positional_multiple_occurrences_is_dotted() { let cmd = Command::new("test").arg( Arg::new("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ); @@ -2542,7 +2556,7 @@ OPTIONS: let cmd = Command::new("test").arg( Arg::new("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .value_name("BAR") .multiple_values(true) .action(ArgAction::Append), @@ -2571,7 +2585,7 @@ fn too_few_value_names_is_dotted() { Arg::new("foo") .long("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .number_of_values(3) .value_names(&["one", "two"]), ); @@ -2599,7 +2613,7 @@ fn too_many_value_names_panics() { Arg::new("foo") .long("foo") .required(true) - .takes_value(true) + .action(ArgAction::Set) .number_of_values(1) .value_names(&["one", "two"]), ) @@ -2637,8 +2651,8 @@ fn disabled_help_flag_and_subcommand() { #[test] fn override_help_subcommand() { let cmd = Command::new("bar") - .subcommand(Command::new("help").arg(Arg::new("arg").takes_value(true))) - .subcommand(Command::new("not_help").arg(Arg::new("arg").takes_value(true))) + .subcommand(Command::new("help").arg(Arg::new("arg").action(ArgAction::Set))) + .subcommand(Command::new("not_help").arg(Arg::new("arg").action(ArgAction::Set))) .disable_help_subcommand(true); let matches = cmd.try_get_matches_from(&["bar", "help", "foo"]).unwrap(); assert_eq!( @@ -2769,7 +2783,7 @@ OPTIONS: .arg(Arg::new("TARGET").required(true).help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .required(true) .help("some"), ) @@ -2793,7 +2807,7 @@ OPTIONS: .arg(Arg::new("TARGET").required(true).help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .required(true) .help("some"), ) @@ -2817,7 +2831,7 @@ OPTIONS: .arg(Arg::new("TARGET").required(true).help("some")) .arg( Arg::new("ARGS") - .takes_value(true) + .action(ArgAction::Set) .required(true) .help("some"), ) diff --git a/tests/builder/help_env.rs b/tests/builder/help_env.rs index 5b8c2e8aa2e..8ab74c7d7dc 100644 --- a/tests/builder/help_env.rs +++ b/tests/builder/help_env.rs @@ -2,7 +2,7 @@ use std::env; -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; use super::utils; @@ -106,7 +106,7 @@ fn hide_env() { .hide_env(true) .env("ENVVAR") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", HIDE_ENV, false); @@ -123,7 +123,7 @@ fn show_env() { .value_name("FILE") .env("ENVVAR") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", SHOW_ENV, false); @@ -141,7 +141,7 @@ fn hide_env_vals() { .hide_env_values(true) .env("ENVVAR") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", HIDE_ENV_VALS, false); @@ -158,7 +158,7 @@ fn show_env_vals() { .value_name("FILE") .env("ENVVAR") .help("A coffeehouse, coffee shop, or café.") - .takes_value(true), + .action(ArgAction::Set), ); utils::assert_output(cmd, "ctest --help", SHOW_ENV_VALS, false); diff --git a/tests/builder/hidden_args.rs b/tests/builder/hidden_args.rs index c6838521dc6..80e7e3f87de 100644 --- a/tests/builder/hidden_args.rs +++ b/tests/builder/hidden_args.rs @@ -1,6 +1,6 @@ use super::utils; -use clap::{arg, Arg, Command}; +use clap::{arg, Arg, ArgAction, Command}; static HIDDEN_ARGS: &str = "test 1.4 Kevin K. @@ -56,10 +56,12 @@ fn hide_short_args() { .short('c') .long("config") .hide_short_help(true) + .action(ArgAction::SetTrue) .help("Some help text describing the --config arg"), Arg::new("visible") .short('v') .long("visible") + .action(ArgAction::SetTrue) .help("This text should be visible"), ]); @@ -99,10 +101,12 @@ OPTIONS: .short('c') .long("config") .hide_short_help(true) + .action(ArgAction::SetTrue) .help("Some help text describing the --config arg"), Arg::new("visible") .short('v') .long("visible") + .action(ArgAction::SetTrue) .help("This text should be visible"), ]); @@ -138,10 +142,12 @@ fn hide_long_args() { .short('c') .long("config") .hide_long_help(true) + .action(ArgAction::SetTrue) .help("Some help text describing the --config arg"), Arg::new("visible") .short('v') .long("visible") + .action(ArgAction::SetTrue) .help("This text should be visible"), ]); @@ -173,10 +179,12 @@ fn hide_long_args_short_help() { .short('c') .long("config") .hide_long_help(true) + .action(ArgAction::SetTrue) .help("Some help text describing the --config arg"), Arg::new("visible") .short('v') .long("visible") + .action(ArgAction::SetTrue) .help("This text should be visible"), ]); diff --git a/tests/builder/ignore_errors.rs b/tests/builder/ignore_errors.rs index 3bfd1c78606..c98cfc2e142 100644 --- a/tests/builder/ignore_errors.rs +++ b/tests/builder/ignore_errors.rs @@ -89,14 +89,14 @@ fn subcommand() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .help("testing testing"), ) .arg( Arg::new("stuff") .short('x') .long("stuff") - .takes_value(true) + .action(ArgAction::Set) .help("stuf value"), ), ) diff --git a/tests/builder/indices.rs b/tests/builder/indices.rs index c5f236fd07c..5b5f0369648 100644 --- a/tests/builder/indices.rs +++ b/tests/builder/indices.rs @@ -6,14 +6,14 @@ fn indices_mult_opts() { .arg( Arg::new("exclude") .short('e') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) .arg( Arg::new("include") .short('i') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec!["ind", "-e", "A", "B", "-i", "B", "C", "-e", "C"]) @@ -35,14 +35,14 @@ fn index_mult_opts() { .arg( Arg::new("exclude") .short('e') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) .arg( Arg::new("include") .short('i') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec!["ind", "-e", "A", "B", "-i", "B", "C", "-e", "C"]) @@ -55,8 +55,8 @@ fn index_mult_opts() { #[test] fn index_flag() { let m = Command::new("ind") - .arg(Arg::new("exclude").short('e')) - .arg(Arg::new("include").short('i')) + .arg(Arg::new("exclude").short('e').action(ArgAction::SetTrue)) + .arg(Arg::new("include").short('i').action(ArgAction::SetTrue)) .try_get_matches_from(vec!["ind", "-e", "-i"]) .unwrap(); @@ -105,7 +105,7 @@ fn indices_mult_flags_opt_combined() { let m = Command::new("ind") .arg(Arg::new("exclude").short('e').action(ArgAction::SetTrue)) .arg(Arg::new("include").short('i').action(ArgAction::SetTrue)) - .arg(Arg::new("option").short('o').takes_value(true)) + .arg(Arg::new("option").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["ind", "-eieeio", "val"]) .unwrap(); @@ -119,7 +119,7 @@ fn indices_mult_flags_opt_combined_eq() { let m = Command::new("ind") .arg(Arg::new("exclude").short('e').action(ArgAction::SetTrue)) .arg(Arg::new("include").short('i').action(ArgAction::SetTrue)) - .arg(Arg::new("option").short('o').takes_value(true)) + .arg(Arg::new("option").short('o').action(ArgAction::Set)) .try_get_matches_from(vec!["ind", "-eieeio=val"]) .unwrap(); @@ -134,7 +134,7 @@ fn indices_mult_opt_value_delim_eq() { .arg( Arg::new("option") .short('o') - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(true) .multiple_values(true), ) @@ -152,7 +152,7 @@ fn indices_mult_opt_value_no_delim_eq() { .arg( Arg::new("option") .short('o') - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec!["myapp", "-o=val1,val2,val3"]) diff --git a/tests/builder/multiple_values.rs b/tests/builder/multiple_values.rs index 7e17e2f5891..0cfcfadc964 100644 --- a/tests/builder/multiple_values.rs +++ b/tests/builder/multiple_values.rs @@ -7,7 +7,7 @@ fn option_long() { Arg::new("option") .long("option") .help("multiple options") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) @@ -35,7 +35,7 @@ fn option_short() { Arg::new("option") .short('o') .help("multiple options") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) @@ -62,7 +62,7 @@ fn option_mixed() { .long("option") .short('o') .help("multiple options") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .action(ArgAction::Append), ) @@ -365,7 +365,7 @@ fn positional() { .arg( Arg::new("pos") .help("multiple positionals") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3"]); @@ -727,7 +727,7 @@ fn no_sep() { Arg::new("option") .long("option") .help("multiple options") - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(false), ) .try_get_matches_from(vec!["", "--option=val1,val2,val3"]); @@ -748,7 +748,7 @@ fn no_sep_positional() { .arg( Arg::new("option") .help("multiple options") - .takes_value(true) + .action(ArgAction::Set) .use_value_delimiter(false), ) .try_get_matches_from(vec!["", "val1,val2,val3"]); @@ -775,7 +775,7 @@ fn req_delimiter_long() { ) .arg( Arg::new("args") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .index(1), ) @@ -813,7 +813,7 @@ fn req_delimiter_long_with_equal() { ) .arg( Arg::new("args") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .index(1), ) @@ -851,7 +851,7 @@ fn req_delimiter_short_with_space() { ) .arg( Arg::new("args") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .index(1), ) @@ -889,7 +889,7 @@ fn req_delimiter_short_with_no_space() { ) .arg( Arg::new("args") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .index(1), ) @@ -927,7 +927,7 @@ fn req_delimiter_short_with_equal() { ) .arg( Arg::new("args") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .index(1), ) @@ -965,12 +965,7 @@ fn req_delimiter_complex() { .use_value_delimiter(true) .require_value_delimiter(true), ) - .arg( - Arg::new("args") - .takes_value(true) - .multiple_values(true) - .index(1), - ) + .arg(Arg::new("args").multiple_values(true).index(1)) .try_get_matches_from(vec![ "", "val1", @@ -1038,7 +1033,7 @@ fn low_index_positional_not_required() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1056,14 +1051,14 @@ fn low_index_positional_last_multiple_too() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) .arg( Arg::new("target") .index(2) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1080,7 +1075,7 @@ fn low_index_positional_too_far_back() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1095,7 +1090,7 @@ fn low_index_positional() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1128,7 +1123,7 @@ fn low_index_positional_in_subcmd() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1162,11 +1157,11 @@ fn low_index_positional_with_option() { Arg::new("files") .required(true) .index(1) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg(Arg::new("target").index(2).required(true)) - .arg(Arg::new("opt").long("option").takes_value(true)) + .arg(Arg::new("opt").long("option").action(ArgAction::Set)) .try_get_matches_from(vec![ "lip", "file1", "file2", "file3", "target", "--option", "test", ]); @@ -1199,7 +1194,7 @@ fn low_index_positional_with_flag() { .arg( Arg::new("files") .index(1) - .takes_value(true) + .action(ArgAction::Set) .required(true) .multiple_values(true), ) @@ -1268,7 +1263,7 @@ fn multiple_value_terminator_option() { Arg::new("files") .short('f') .value_terminator(";") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg(Arg::new("other")) @@ -1299,7 +1294,7 @@ fn multiple_value_terminator_option_other_arg() { Arg::new("files") .short('f') .value_terminator(";") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ) .arg(Arg::new("other")) @@ -1330,7 +1325,7 @@ fn multiple_vals_with_hyphen() { let res = Command::new("do") .arg( Arg::new("cmds") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .allow_hyphen_values(true) .value_terminator(";"), diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index 3690c596453..5707063dff1 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -37,7 +37,7 @@ fn require_equals_fail() { Arg::new("cfg") .require_equals(true) .value_parser(clap::builder::NonEmptyStringValueParser::new()) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .try_get_matches_from(vec!["prog", "--config", "file.conf"]); @@ -58,7 +58,7 @@ For more information try --help let cmd = Command::new("prog").arg( Arg::new("cfg") .require_equals(true) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ); utils::assert_output(cmd, "prog --config file.conf", NO_EQUALS, true); @@ -69,7 +69,7 @@ fn require_equals_min_values_zero() { let res = Command::new("prog") .arg( Arg::new("cfg") - .takes_value(true) + .action(ArgAction::Set) .require_equals(true) .min_values(0) .long("config"), @@ -87,7 +87,7 @@ fn double_hyphen_as_value() { let res = Command::new("prog") .arg( Arg::new("cfg") - .takes_value(true) + .action(ArgAction::Set) .allow_hyphen_values(true) .long("config"), ) @@ -104,7 +104,7 @@ fn require_equals_no_empty_values_fail() { let res = Command::new("prog") .arg( Arg::new("cfg") - .takes_value(true) + .action(ArgAction::Set) .require_equals(true) .value_parser(clap::builder::NonEmptyStringValueParser::new()) .long("config"), @@ -120,7 +120,7 @@ fn require_equals_empty_vals_pass() { let res = Command::new("prog") .arg( Arg::new("cfg") - .takes_value(true) + .action(ArgAction::Set) .require_equals(true) .long("config"), ) @@ -133,7 +133,7 @@ fn require_equals_pass() { let res = Command::new("prog") .arg( Arg::new("cfg") - .takes_value(true) + .action(ArgAction::Set) .require_equals(true) .long("config"), ) @@ -482,7 +482,7 @@ fn leading_hyphen_with_only_pos_follows() { .arg( arg!(o: -o [opt] ... "some opt") .number_of_values(1) - .takes_value(true) + .action(ArgAction::Set) .allow_hyphen_values(true), ) .arg(arg!([arg] "some arg")) @@ -513,7 +513,7 @@ fn issue_1047_min_zero_vals_default_val() { Arg::new("del") .short('d') .long("del") - .takes_value(true) + .action(ArgAction::Set) .require_equals(true) .min_values(0) .default_missing_value("default"), @@ -591,8 +591,16 @@ fn issue_1105_empty_value_short_explicit_no_space() { #[cfg(feature = "suggestions")] fn issue_1073_suboptimal_flag_suggestion() { let cmd = Command::new("ripgrep-616") - .arg(Arg::new("files-with-matches").long("files-with-matches")) - .arg(Arg::new("files-without-match").long("files-without-match")); + .arg( + Arg::new("files-with-matches") + .long("files-with-matches") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("files-without-match") + .long("files-without-match") + .action(ArgAction::SetTrue), + ); utils::assert_output( cmd, "ripgrep-616 --files-without-matches", @@ -697,7 +705,7 @@ fn infer_long_arg() { .alias("autobahn") .action(ArgAction::SetTrue), ) - .arg(Arg::new("racecar").long("racecar").takes_value(true)); + .arg(Arg::new("racecar").long("racecar").action(ArgAction::Set)); let matches = cmd .clone() diff --git a/tests/builder/positionals.rs b/tests/builder/positionals.rs index 401044cb462..7490a238b7d 100644 --- a/tests/builder/positionals.rs +++ b/tests/builder/positionals.rs @@ -23,7 +23,7 @@ fn issue_946() { .arg( clap::Arg::new("filter") .index(1) - .takes_value(true) + .action(ArgAction::Set) .help("filters to apply to output"), ) .try_get_matches_from(vec!["compiletest", "--exact"]); @@ -120,7 +120,7 @@ fn positional_multiple() { arg!(-f --flag "some flag").action(ArgAction::SetTrue), Arg::new("positional") .index(1) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ]) .try_get_matches_from(vec!["", "-f", "test1", "test2", "test3"]); @@ -144,7 +144,7 @@ fn positional_multiple_3() { arg!(-f --flag "some flag").action(ArgAction::SetTrue), Arg::new("positional") .index(1) - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true), ]) .try_get_matches_from(vec!["", "test1", "test2", "test3", "--flag"]); @@ -338,7 +338,7 @@ fn ignore_hyphen_values_on_last() { clap::Arg::new("name") .long("name") .short('n') - .takes_value(true) + .action(ArgAction::Set) .required(false), ); diff --git a/tests/builder/possible_values.rs b/tests/builder/possible_values.rs index d4d8a04b0b7..f6021964d2e 100644 --- a/tests/builder/possible_values.rs +++ b/tests/builder/possible_values.rs @@ -88,7 +88,7 @@ fn possible_values_of_positional_multiple() { .arg( Arg::new("positional") .index(1) - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .multiple_values(true), ) @@ -113,7 +113,7 @@ fn possible_values_of_positional_multiple_fail() { .arg( Arg::new("positional") .index(1) - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .multiple_values(true), ) @@ -130,7 +130,7 @@ fn possible_values_of_option() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123"]), ) .try_get_matches_from(vec!["myprog", "--option", "test123"]); @@ -152,7 +152,7 @@ fn possible_values_of_option_fail() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123"]), ) .try_get_matches_from(vec!["myprog", "--option", "notest"]); @@ -168,7 +168,7 @@ fn possible_values_of_option_multiple() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .action(ArgAction::Append), ) @@ -194,7 +194,7 @@ fn possible_values_of_option_multiple_fail() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .action(ArgAction::Append), ) @@ -210,7 +210,7 @@ fn possible_values_output() { Command::new("test").arg( Arg::new("option") .short('O') - .takes_value(true) + .action(ArgAction::Set) .value_parser(["slow", "fast", "ludicrous speed"]), ), "clap-test -O slo", @@ -225,7 +225,7 @@ fn possible_values_alias_output() { Command::new("test").arg( Arg::new("option") .short('O') - .takes_value(true) + .action(ArgAction::Set) .value_parser([ "slow".into(), PossibleValue::new("fast").alias("fost"), @@ -244,7 +244,7 @@ fn possible_values_hidden_output() { Command::new("test").arg( Arg::new("option") .short('O') - .takes_value(true) + .action(ArgAction::Set) .value_parser([ "slow".into(), "fast".into(), @@ -264,7 +264,7 @@ fn escaped_possible_values_output() { Command::new("test").arg( Arg::new("option") .short('O') - .takes_value(true) + .action(ArgAction::Set) .value_parser(["slow", "fast", "ludicrous speed"]), ), "clap-test -O ludicrous", @@ -279,7 +279,7 @@ fn missing_possible_value_error() { Command::new("test").arg( Arg::new("option") .short('O') - .takes_value(true) + .action(ArgAction::Set) .value_parser([ "slow".into(), PossibleValue::new("fast").alias("fost"), @@ -307,7 +307,7 @@ fn alias() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser([PossibleValue::new("test123").alias("123"), "test321".into()]) .ignore_case(true), ) @@ -329,7 +329,7 @@ fn aliases() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser([ PossibleValue::new("test123").aliases(["1", "2", "3"]), "test321".into(), @@ -354,7 +354,7 @@ fn ignore_case() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .ignore_case(true), ) @@ -376,7 +376,7 @@ fn ignore_case_fail() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]), ) .try_get_matches_from(vec!["pv", "--option", "TeSt123"]); @@ -392,7 +392,7 @@ fn ignore_case_multiple() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .multiple_values(true) .ignore_case(true), @@ -417,7 +417,7 @@ fn ignore_case_multiple_fail() { Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(ArgAction::Set) .value_parser(["test123", "test321"]) .multiple_values(true), ) diff --git a/tests/builder/propagate_globals.rs b/tests/builder/propagate_globals.rs index c528c01b30a..f486c0c7b24 100644 --- a/tests/builder/propagate_globals.rs +++ b/tests/builder/propagate_globals.rs @@ -7,7 +7,7 @@ fn get_app() -> Command<'static> { .long("global-arg") .help("Specifies something needed by the subcommands") .global(true) - .takes_value(true) + .action(ArgAction::Set) .default_value("default_value"), ) .arg( diff --git a/tests/builder/require.rs b/tests/builder/require.rs index 7b480538b23..55a477b8a67 100644 --- a/tests/builder/require.rs +++ b/tests/builder/require.rs @@ -313,7 +313,7 @@ fn required_unless_present() { .arg( Arg::new("cfg") .required_unless_present("dbg") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) @@ -331,7 +331,7 @@ fn required_unless_present_err() { .arg( Arg::new("cfg") .required_unless_present("dbg") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug")) @@ -348,7 +348,7 @@ fn required_unless_present_with_optional_value() { .arg( Arg::new("cfg") .required_unless_present("dbg") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug")) @@ -366,11 +366,11 @@ fn required_unless_present_all() { .arg( Arg::new("cfg") .required_unless_present_all(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessall", "--debug", "-i", "file"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -386,11 +386,11 @@ fn required_unless_all_err() { .arg( Arg::new("cfg") .required_unless_present_all(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("dbg").long("debug")) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessall", "--debug"]); assert!(res.is_err()); @@ -405,11 +405,11 @@ fn required_unless_present_any() { .arg( Arg::new("cfg") .required_unless_present_any(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessone", "--debug"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -426,11 +426,11 @@ fn required_unless_any_2() { .arg( Arg::new("cfg") .required_unless_present_any(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessone", "-i", "file"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -443,11 +443,17 @@ fn required_unless_any_2() { fn required_unless_any_works_with_short() { // GitHub issue: https://github.com/clap-rs/clap/issues/1135 let res = Command::new("unlessone") - .arg(Arg::new("a").conflicts_with("b").short('a')) - .arg(Arg::new("b").short('b')) + .arg( + Arg::new("a") + .conflicts_with("b") + .short('a') + .action(ArgAction::SetTrue), + ) + .arg(Arg::new("b").short('b').action(ArgAction::SetTrue)) .arg( Arg::new("x") .short('x') + .action(ArgAction::SetTrue) .required_unless_present_any(&["a", "b"]), ) .try_get_matches_from(vec!["unlessone", "-a"]); @@ -458,11 +464,17 @@ fn required_unless_any_works_with_short() { #[test] fn required_unless_any_works_with_short_err() { let res = Command::new("unlessone") - .arg(Arg::new("a").conflicts_with("b").short('a')) - .arg(Arg::new("b").short('b')) + .arg( + Arg::new("a") + .conflicts_with("b") + .short('a') + .action(ArgAction::SetTrue), + ) + .arg(Arg::new("b").short('b').action(ArgAction::SetTrue)) .arg( Arg::new("x") .short('x') + .action(ArgAction::SetTrue) .required_unless_present_any(&["a", "b"]), ) .try_get_matches_from(vec!["unlessone"]); @@ -473,8 +485,13 @@ fn required_unless_any_works_with_short_err() { #[test] fn required_unless_any_works_without() { let res = Command::new("unlessone") - .arg(Arg::new("a").conflicts_with("b").short('a')) - .arg(Arg::new("b").short('b')) + .arg( + Arg::new("a") + .conflicts_with("b") + .short('a') + .action(ArgAction::SetTrue), + ) + .arg(Arg::new("b").short('b').action(ArgAction::SetTrue)) .arg(Arg::new("x").required_unless_present_any(&["a", "b"])) .try_get_matches_from(vec!["unlessone", "-a"]); @@ -484,11 +501,17 @@ fn required_unless_any_works_without() { #[test] fn required_unless_any_works_with_long() { let res = Command::new("unlessone") - .arg(Arg::new("a").conflicts_with("b").short('a')) - .arg(Arg::new("b").short('b')) + .arg( + Arg::new("a") + .conflicts_with("b") + .short('a') + .action(ArgAction::SetTrue), + ) + .arg(Arg::new("b").short('b').action(ArgAction::SetTrue)) .arg( Arg::new("x") .long("x_is_the_option") + .action(ArgAction::SetTrue) .required_unless_present_any(&["a", "b"]), ) .try_get_matches_from(vec!["unlessone", "-a"]); @@ -502,11 +525,11 @@ fn required_unless_any_1() { .arg( Arg::new("cfg") .required_unless_present_any(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessone", "--debug"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -522,11 +545,11 @@ fn required_unless_any_err() { .arg( Arg::new("cfg") .required_unless_present_any(&["dbg", "infile"]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("dbg").long("debug")) - .arg(Arg::new("infile").short('i').takes_value(true)) + .arg(Arg::new("dbg").long("debug").action(ArgAction::SetTrue)) + .arg(Arg::new("infile").short('i').action(ArgAction::Set)) .try_get_matches_from(vec!["unlessone"]); assert!(res.is_err()); @@ -546,10 +569,10 @@ fn requires_if_present_val() { .arg( Arg::new("cfg") .requires_if("my.cfg", "extra") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").long("extra")) + .arg(Arg::new("extra").long("extra").action(ArgAction::SetTrue)) .try_get_matches_from(vec!["unlessone", "--config=my.cfg"]); assert!(res.is_err()); @@ -562,11 +585,11 @@ fn requires_if_present_mult() { .arg( Arg::new("cfg") .requires_ifs(&[("my.cfg", "extra"), ("other.cfg", "other")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").long("extra")) - .arg(Arg::new("other").long("other")) + .arg(Arg::new("extra").long("extra").action(ArgAction::SetTrue)) + .arg(Arg::new("other").long("other").action(ArgAction::SetTrue)) .try_get_matches_from(vec!["unlessone", "--config=other.cfg"]); assert!(res.is_err()); @@ -579,11 +602,11 @@ fn requires_if_present_mult_pass() { .arg( Arg::new("cfg") .requires_ifs(&[("my.cfg", "extra"), ("other.cfg", "other")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").long("extra")) - .arg(Arg::new("other").long("other")) + .arg(Arg::new("extra").long("extra").action(ArgAction::SetTrue)) + .arg(Arg::new("other").long("other").action(ArgAction::SetTrue)) .try_get_matches_from(vec!["unlessone", "--config=some.cfg"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -595,10 +618,10 @@ fn requires_if_present_val_no_present_pass() { .arg( Arg::new("cfg") .requires_if("my.cfg", "extra") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").long("extra")) + .arg(Arg::new("extra").long("extra").action(ArgAction::SetTrue)) .try_get_matches_from(vec!["unlessone"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -612,10 +635,10 @@ fn required_if_val_present_pass() { .arg( Arg::new("cfg") .required_if_eq("extra", "val") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) .try_get_matches_from(vec!["ri", "--extra", "val", "--config", "my.cfg"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -627,10 +650,10 @@ fn required_if_val_present_fail() { .arg( Arg::new("cfg") .required_if_eq("extra", "val") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) .try_get_matches_from(vec!["ri", "--extra", "val"]); assert!(res.is_err()); @@ -643,12 +666,12 @@ fn required_if_val_present_ignore_case_pass() { .arg( Arg::new("cfg") .required_if_eq("extra", "Val") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg( Arg::new("extra") - .takes_value(true) + .action(ArgAction::Set) .long("extra") .ignore_case(true), ) @@ -663,12 +686,12 @@ fn required_if_val_present_ignore_case_fail() { .arg( Arg::new("cfg") .required_if_eq("extra", "Val") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) .arg( Arg::new("extra") - .takes_value(true) + .action(ArgAction::Set) .long("extra") .ignore_case(true), ) @@ -684,11 +707,11 @@ fn required_if_all_values_present_pass() { .arg( Arg::new("cfg") .required_if_eq_all(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec![ "ri", "--extra", "val", "--option", "spec", "--config", "my.cfg", ]); @@ -702,11 +725,11 @@ fn required_if_some_values_present_pass() { .arg( Arg::new("cfg") .required_if_eq_all(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--extra", "val"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -718,11 +741,11 @@ fn required_if_all_values_present_fail() { .arg( Arg::new("cfg") .required_if_eq_all(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--extra", "val", "--option", "spec"]); assert!(res.is_err()); @@ -736,11 +759,11 @@ fn required_if_any_all_values_present_pass() { Arg::new("cfg") .required_if_eq_all(&[("extra", "val"), ("option", "spec")]) .required_if_eq_any(&[("extra", "val2"), ("option", "spec2")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec![ "ri", "--extra", "val", "--option", "spec", "--config", "my.cfg", ]); @@ -755,11 +778,11 @@ fn required_if_any_all_values_present_fail() { Arg::new("cfg") .required_if_eq_all(&[("extra", "val"), ("option", "spec")]) .required_if_eq_any(&[("extra", "val2"), ("option", "spec2")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--extra", "val", "--option", "spec"]); assert!(res.is_err()); @@ -774,20 +797,20 @@ fn list_correct_required_args() { .about("Arg test") .arg( Arg::new("target") - .takes_value(true) + .action(ArgAction::Set) .required(true) .value_parser(["file", "stdout"]) .long("target"), ) .arg( Arg::new("input") - .takes_value(true) + .action(ArgAction::Set) .required(true) .long("input"), ) .arg( Arg::new("output") - .takes_value(true) + .action(ArgAction::Set) .required(true) .long("output"), ); @@ -808,20 +831,20 @@ fn required_if_val_present_fail_error_output() { .about("Arg test") .arg( Arg::new("target") - .takes_value(true) + .action(ArgAction::Set) .required(true) .value_parser(["file", "stdout"]) .long("target"), ) .arg( Arg::new("input") - .takes_value(true) + .action(ArgAction::Set) .required(true) .long("input"), ) .arg( Arg::new("output") - .takes_value(true) + .action(ArgAction::Set) .required_if_eq("target", "file") .long("output"), ); @@ -840,10 +863,10 @@ fn required_if_wrong_val() { .arg( Arg::new("cfg") .required_if_eq("extra", "val") - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) .try_get_matches_from(vec!["ri", "--extra", "other"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -855,11 +878,11 @@ fn required_ifs_val_present_pass() { .arg( Arg::new("cfg") .required_if_eq_any(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("option").takes_value(true).long("option")) - .arg(Arg::new("extra").takes_value(true).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) .try_get_matches_from(vec!["ri", "--option", "spec", "--config", "my.cfg"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -871,11 +894,11 @@ fn required_ifs_val_present_fail() { .arg( Arg::new("cfg") .required_if_eq_any(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--option", "spec"]); assert!(res.is_err()); @@ -888,11 +911,11 @@ fn required_ifs_wrong_val() { .arg( Arg::new("cfg") .required_if_eq_any(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--option", "other"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -904,11 +927,11 @@ fn required_ifs_wrong_val_mult_fail() { .arg( Arg::new("cfg") .required_if_eq_any(&[("extra", "val"), ("option", "spec")]) - .takes_value(true) + .action(ArgAction::Set) .long("config"), ) - .arg(Arg::new("extra").takes_value(true).long("extra")) - .arg(Arg::new("option").takes_value(true).long("option")) + .arg(Arg::new("extra").action(ArgAction::Set).long("extra")) + .arg(Arg::new("option").action(ArgAction::Set).long("option")) .try_get_matches_from(vec!["ri", "--extra", "other", "--option", "spec"]); assert!(res.is_err()); @@ -1047,28 +1070,28 @@ For more information try --help .arg( Arg::new("a") .long("a") - .takes_value(true) + .action(ArgAction::Set) .required_unless_present("b") .conflicts_with("b"), ) .arg( Arg::new("b") .long("b") - .takes_value(true) + .action(ArgAction::Set) .required_unless_present("a") .conflicts_with("a"), ) .arg( Arg::new("c") .long("c") - .takes_value(true) + .action(ArgAction::Set) .required_unless_present("d") .conflicts_with("d"), ) .arg( Arg::new("d") .long("d") - .takes_value(true) + .action(ArgAction::Set) .required_unless_present("c") .conflicts_with("c"), ); @@ -1099,7 +1122,7 @@ fn issue_1643_args_mutually_require_each_other() { .help("The relation id to get the data from") .long("relation-id") .short('r') - .takes_value(true) + .action(ArgAction::Set) .requires("remote_unit_name"), ) .arg( @@ -1107,7 +1130,7 @@ fn issue_1643_args_mutually_require_each_other() { .help("The name of the remote unit to get data from") .long("remote-unit") .short('u') - .takes_value(true) + .action(ArgAction::Set) .requires("relation_id"), ); @@ -1394,13 +1417,13 @@ fn required_error_doesnt_duplicate() { .arg( Arg::new("b") .short('b') - .takes_value(true) + .action(ArgAction::Set) .conflicts_with("c"), ) .arg( Arg::new("c") .short('c') - .takes_value(true) + .action(ArgAction::Set) .conflicts_with("b"), ); const EXPECTED: &str = "\ diff --git a/tests/builder/subcommands.rs b/tests/builder/subcommands.rs index 3ff0676f40e..879d92cb79f 100644 --- a/tests/builder/subcommands.rs +++ b/tests/builder/subcommands.rs @@ -75,7 +75,7 @@ fn subcommand() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .help("testing testing"), ), ) @@ -100,7 +100,7 @@ fn subcommand_none_given() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .help("testing testing"), ), ) @@ -119,7 +119,7 @@ fn subcommand_multiple() { Arg::new("test") .short('t') .long("test") - .takes_value(true) + .action(ArgAction::Set) .help("testing testing"), ), Command::new("add").arg(Arg::new("roster").short('r')), @@ -300,10 +300,10 @@ fn issue_1161_multiple_hyphen_hyphen() { // from example 22 let res = Command::new("myprog") .arg(Arg::new("eff").short('f')) - .arg(Arg::new("pea").short('p').takes_value(true)) + .arg(Arg::new("pea").short('p').action(ArgAction::Set)) .arg( Arg::new("slop") - .takes_value(true) + .action(ArgAction::Set) .multiple_values(true) .last(true), ) diff --git a/tests/builder/unicode.rs b/tests/builder/unicode.rs index aa9bad55001..03f2c65c69a 100644 --- a/tests/builder/unicode.rs +++ b/tests/builder/unicode.rs @@ -7,7 +7,7 @@ fn possible_values_ignore_case() { clap::Arg::new("option") .short('o') .long("option") - .takes_value(true) + .action(clap::ArgAction::Set) .value_parser(["ä"]) .ignore_case(true), ) diff --git a/tests/builder/utf8.rs b/tests/builder/utf8.rs index 15f115b9815..1d3b486378a 100644 --- a/tests/builder/utf8.rs +++ b/tests/builder/utf8.rs @@ -1,6 +1,6 @@ #![cfg(not(windows))] -use clap::{arg, error::ErrorKind, value_parser, Arg, Command}; +use clap::{arg, error::ErrorKind, value_parser, Arg, ArgAction, Command}; use std::ffi::OsString; use std::os::unix::ffi::OsStringExt; @@ -16,7 +16,12 @@ fn invalid_utf8_strict_positional() { #[test] fn invalid_utf8_strict_option_short_space() { let m = Command::new("bad_utf8") - .arg(Arg::new("arg").short('a').long("arg").takes_value(true)) + .arg( + Arg::new("arg") + .short('a') + .long("arg") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![ OsString::from(""), OsString::from("-a"), @@ -29,7 +34,12 @@ fn invalid_utf8_strict_option_short_space() { #[test] fn invalid_utf8_strict_option_short_equals() { let m = Command::new("bad_utf8") - .arg(Arg::new("arg").short('a').long("arg").takes_value(true)) + .arg( + Arg::new("arg") + .short('a') + .long("arg") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![ OsString::from(""), OsString::from_vec(vec![0x2d, 0x61, 0x3d, 0xe9]), @@ -41,7 +51,12 @@ fn invalid_utf8_strict_option_short_equals() { #[test] fn invalid_utf8_strict_option_short_no_space() { let m = Command::new("bad_utf8") - .arg(Arg::new("arg").short('a').long("arg").takes_value(true)) + .arg( + Arg::new("arg") + .short('a') + .long("arg") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![ OsString::from(""), OsString::from_vec(vec![0x2d, 0x61, 0xe9]), @@ -53,7 +68,12 @@ fn invalid_utf8_strict_option_short_no_space() { #[test] fn invalid_utf8_strict_option_long_space() { let m = Command::new("bad_utf8") - .arg(Arg::new("arg").short('a').long("arg").takes_value(true)) + .arg( + Arg::new("arg") + .short('a') + .long("arg") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![ OsString::from(""), OsString::from("--arg"), @@ -66,7 +86,12 @@ fn invalid_utf8_strict_option_long_space() { #[test] fn invalid_utf8_strict_option_long_equals() { let m = Command::new("bad_utf8") - .arg(Arg::new("arg").short('a').long("arg").takes_value(true)) + .arg( + Arg::new("arg") + .short('a') + .long("arg") + .action(ArgAction::Set), + ) .try_get_matches_from(vec![ OsString::from(""), OsString::from_vec(vec![0x2d, 0x2d, 0x61, 0x72, 0x67, 0x3d, 0xe9]), @@ -96,7 +121,7 @@ fn invalid_utf8_option_short_space() { Arg::new("arg") .short('a') .long("arg") - .takes_value(true) + .action(ArgAction::Set) .value_parser(value_parser!(OsString)), ) .try_get_matches_from(vec![ @@ -120,7 +145,7 @@ fn invalid_utf8_option_short_equals() { Arg::new("arg") .short('a') .long("arg") - .takes_value(true) + .action(ArgAction::Set) .value_parser(value_parser!(OsString)), ) .try_get_matches_from(vec![ @@ -143,7 +168,7 @@ fn invalid_utf8_option_short_no_space() { Arg::new("arg") .short('a') .long("arg") - .takes_value(true) + .action(ArgAction::Set) .value_parser(value_parser!(OsString)), ) .try_get_matches_from(vec![ @@ -166,7 +191,7 @@ fn invalid_utf8_option_long_space() { Arg::new("arg") .short('a') .long("arg") - .takes_value(true) + .action(ArgAction::Set) .value_parser(value_parser!(OsString)), ) .try_get_matches_from(vec![ @@ -190,7 +215,7 @@ fn invalid_utf8_option_long_equals() { Arg::new("arg") .short('a') .long("arg") - .takes_value(true) + .action(ArgAction::Set) .value_parser(value_parser!(OsString)), ) .try_get_matches_from(vec![