Lines Matching defs:Arg

29 /// There are two methods for constructing [`Arg`]s, using the builder pattern and setting options
33 /// - [Basic API][crate::Arg#basic-api]
34 /// - [Value Handling][crate::Arg#value-handling]
35 /// - [Help][crate::Arg#help-1]
36 /// - [Advanced Argument Relations][crate::Arg#advanced-argument-relations]
37 /// - [Reflection][crate::Arg#reflection]
42 /// # use clap::{Arg, arg, ArgAction};
44 /// let cfg = Arg::new("config")
54 pub struct Arg {
89 impl Arg {
90 /// Create a new [`Arg`] with a unique name.
95 /// **NOTE:** In the case of arguments that take values (i.e. [`Arg::action(ArgAction::Set)`])
102 /// # use clap::{Command, Arg};
103 /// Arg::new("config")
106 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
108 Arg::default().id(id)
113 /// See [`Arg::new`] for more details.
133 /// # use clap::{Command, Arg, ArgAction};
135 /// .arg(Arg::new("config")
147 /// # use clap::{Command, Arg, ArgAction};
150 /// .arg(Arg::new("host")
153 /// .arg(Arg::new("help")
193 /// # use clap::{Command, Arg, ArgAction};
195 /// .arg(Arg::new("cfg")
219 /// # use clap::{Command, Arg, ArgAction};
221 /// .arg(Arg::new("test")
248 /// # use clap::{Command, Arg, ArgAction};
250 /// .arg(Arg::new("test")
278 /// # use clap::{Command, Arg, ArgAction};
280 /// .arg(Arg::new("test")
306 /// # use clap::{Command, Arg, ArgAction};
308 /// .arg(Arg::new("test")
330 /// Like [`Arg::alias`], except that they are visible inside the help message.
335 /// # use clap::{Command, Arg, ArgAction};
337 /// .arg(Arg::new("test")
346 /// [`Command::alias`]: Arg::alias()
359 /// Like [`Arg::short_alias`], except that they are visible inside the help message.
364 /// # use clap::{Command, Arg, ArgAction};
366 /// .arg(Arg::new("test")
388 /// Like [`Arg::aliases`], except that they are visible inside the help message.
393 /// # use clap::{Command, Arg, ArgAction};
395 /// .arg(Arg::new("test")
404 /// [`Command::aliases`]: Arg::aliases()
414 /// Like [`Arg::short_aliases`], except that they are visible inside the help message.
419 /// # use clap::{Command, Arg, ArgAction};
421 /// .arg(Arg::new("test")
449 /// with [`Arg::short`] or [`Arg::long`].
451 /// **NOTE:** When utilized with [`Arg::num_args(1..)`], only the **last** positional argument
463 /// # use clap::{Command, Arg};
464 /// Arg::new("config")
470 /// # use clap::{Command, Arg, ArgAction};
472 /// .arg(Arg::new("mode")
474 /// .arg(Arg::new("debug")
485 /// [`Arg::short`]: Arg::short()
486 /// [`Arg::long`]: Arg::long()
487 /// [`Arg::num_args(true)`]: Arg::num_args()
500 /// value), set [`allow_hyphen_values`][Arg::allow_hyphen_values]. Either way, users still
503 /// **NOTE:** [`Arg::value_delimiter`] still applies if set.
505 /// **NOTE:** Setting this requires [`Arg::num_args(..)`].
518 /// [`Arg::num_args(..)`]: crate::Arg::num_args()
544 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
550 /// marked [`Arg::required`])
555 /// # use clap::{Arg, ArgAction};
556 /// Arg::new("args")
566 /// # use clap::{Command, Arg, ArgAction};
568 /// .arg(Arg::new("first"))
569 /// .arg(Arg::new("second"))
570 /// .arg(Arg::new("third")
587 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
589 /// .arg(Arg::new("first"))
590 /// .arg(Arg::new("second"))
591 /// .arg(Arg::new("third")
601 /// [index]: Arg::index()
628 /// # use clap::Arg;
629 /// Arg::new("config")
637 /// # use clap::{Command, Arg, ArgAction};
639 /// .arg(Arg::new("cfg")
653 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
655 /// .arg(Arg::new("cfg")
685 /// # use clap::Arg;
686 /// Arg::new("config")
691 /// Setting [`Arg::requires(name)`] requires that the argument be used at runtime if the
696 /// # use clap::{Command, Arg, ArgAction};
698 /// .arg(Arg::new("cfg")
702 /// .arg(Arg::new("input"))
710 /// Setting [`Arg::requires(name)`] and *not* supplying that argument is an error.
713 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
715 /// .arg(Arg::new("cfg")
719 /// .arg(Arg::new("input"))
727 /// [`Arg::requires(name)`]: Arg::requires()
728 /// [Conflicting]: Arg::conflicts_with()
729 /// [override]: Arg::overrides_with()
745 /// # use clap::Arg;
746 /// Arg::new("config")
755 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
757 /// .arg(Arg::new("exclusive")
761 /// .arg(Arg::new("debug")
763 /// .arg(Arg::new("input"))
792 /// want to clutter the source with three duplicate [`Arg`] definitions.
795 /// # use clap::{Command, Arg, ArgAction};
797 /// .arg(Arg::new("verb")
851 impl Arg {
865 /// # use clap::Arg;
868 /// Arg::new("flag")
907 /// clap::Arg::new("color")
913 /// clap::Arg::new("hostname")
920 /// clap::Arg::new("port")
971 /// - It reaches the [`Arg::value_terminator`] if set
974 /// - Use a delimiter between values with [Arg::value_delimiter]
976 /// - Require positional arguments to appear after `--` with [`Arg::last`]
982 /// # use clap::{Command, Arg};
984 /// .arg(Arg::new("mode")
994 /// Flag/option hybrid (see also [default_missing_value][Arg::default_missing_value])
996 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
998 /// .arg(Arg::new("mode")
1025 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
1027 /// .arg(Arg::new("file")
1051 /// # use clap::{Command, Arg, ArgAction};
1053 /// .arg(Arg::new("file")
1057 /// .arg(Arg::new("word"));
1079 /// # use clap::{Command, Arg, ArgAction};
1081 /// .arg(Arg::new("file")
1084 /// .arg(Arg::new("word"))
1103 deprecated(since = "4.0.0", note = "Replaced with `Arg::num_args`")
1116 /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`]
1121 /// # use clap::{Command, Arg};
1122 /// Arg::new("cfg")
1130 /// # use clap::{Command, Arg};
1132 /// .arg(Arg::new("config")
1152 /// [positional]: Arg::index()
1153 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1176 /// **Pro Tip:** It may help to use [`Arg::next_line_help(true)`] if there are long, or
1179 /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`] and [`Arg::num_args(1..)`].
1184 /// # use clap::{Command, Arg};
1185 /// Arg::new("speed")
1192 /// # use clap::{Command, Arg};
1194 /// .arg(Arg::new("io")
1214 /// [`Arg::next_line_help(true)`]: Arg::next_line_help()
1215 /// [`Arg::num_args`]: Arg::num_args()
1216 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1217 /// [`Arg::num_args(1..)`]: Arg::num_args()
1228 /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`].
1233 /// # use clap::{Arg, ValueHint};
1234 /// Arg::new("user")
1243 /// # use clap::{Command, Arg, ValueHint, ArgAction};
1247 /// Arg::new("command")
1263 /// by [`Arg::required_if_eq`], [`Arg::required_if_eq_any`], or
1264 /// [`Arg::required_if_eq_all`] is case-insensitive.
1267 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
1274 /// # use clap::{Command, Arg, ArgAction};
1276 /// .arg(Arg::new("option")
1291 /// # use clap::{Command, Arg, ArgAction};
1293 /// .arg(Arg::new("option")
1320 /// [`allow_negative_numbers`][Arg::allow_negative_numbers].
1322 /// See also [`trailing_var_arg`][Arg::trailing_var_arg].
1324 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
1328 /// `allow_hyphen_values(true)`. When combined with [`Arg::num_args(..)`],
1329 /// [`Arg::value_terminator`] is one way to ensure processing stops.
1332 /// [`Arg::num_args`], as this becomes ambiguous `$ prog --arg -- -- val`. All
1339 /// # use clap::{Command, Arg, ArgAction};
1341 /// .arg(Arg::new("pat")
1352 /// Not setting `Arg::allow_hyphen_values(true)` and supplying a value which starts with a
1356 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
1358 /// .arg(Arg::new("pat")
1368 /// [`Arg::num_args(1)`]: Arg::num_args()
1381 /// This is similar to [`Arg::allow_hyphen_values`] except that it only allows numbers,
1384 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
1389 /// # use clap::{Command, Arg};
1391 /// .arg(Arg::new("num").allow_negative_numbers(true))
1412 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
1420 /// # use clap::{Command, Arg, ArgAction};
1422 /// .arg(Arg::new("cfg")
1437 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
1439 /// .arg(Arg::new("cfg")
1463 deprecated(since = "4.0.0", note = "Replaced with `Arg::value_delimiter`")
1480 /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`]
1485 /// # use clap::{Command, Arg};
1487 /// .arg(Arg::new("config")
1497 /// [`Arg::value_delimiter(',')`]: Arg::value_delimiter()
1498 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1521 /// # use clap::{Command, Arg, ArgAction};
1522 /// Arg::new("vals")
1533 /// # use clap::{Command, Arg, ArgAction};
1535 /// .arg(Arg::new("cmds")
1540 /// .arg(Arg::new("location"))
1548 /// [options]: Arg::action
1549 /// [positional arguments]: Arg::index()
1550 /// [`num_args(1..)`]: Arg::num_args()
1551 /// [`num_args`]: Arg::num_args()
1574 /// **NOTE:** Implicitly sets [`Arg::action(ArgAction::Set)`] [`Arg::num_args(1..)`],
1575 /// [`Arg::allow_hyphen_values(true)`], and [`Arg::last(true)`] when set to `true`.
1577 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1578 /// [`Arg::num_args(1..)`]: Arg::num_args()
1579 /// [`Arg::allow_hyphen_values(true)`]: Arg::allow_hyphen_values()
1580 /// [`Arg::last(true)`]: Arg::last()
1596 /// **NOTE:** This setting is perfectly compatible with [`Arg::default_value_if`] but slightly
1597 /// different. `Arg::default_value` *only* takes effect when the user has not provided this arg
1598 /// at runtime. `Arg::default_value_if` however only takes effect when the user has not provided
1600 /// `Arg::default_value` and `Arg::default_value_if`, and the user **did not** provide this arg
1601 /// at runtime, nor were the conditions met for `Arg::default_value_if`, the `Arg::default_value`
1604 /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`].
1611 /// # use clap::{Command, Arg, parser::ValueSource};
1613 /// .arg(Arg::new("opt")
1628 /// # use clap::{Command, Arg, parser::ValueSource};
1630 /// .arg(Arg::new("opt")
1641 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1643 /// [`Arg::default_value_if`]: Arg::default_value_if()
1660 deprecated(since = "4.0.0", note = "Replaced with `Arg::default_value`")
1668 /// See [`Arg::default_value`].
1670 /// [`Arg::default_value`]: Arg::default_value()
1683 deprecated(since = "4.0.0", note = "Replaced with `Arg::default_values`")
1697 /// [`.num_args(0..N)`][Arg::num_args] and the
1698 /// [`.require_equals(true)`][Arg::require_equals] configuration option. These are required in
1705 /// # use clap::{Command, Arg, parser::ValueSource};
1708 /// .arg(Arg::new("color").long("color")
1743 /// # use clap::{Command, Arg, parser::ValueSource, value_parser};
1746 /// .arg(Arg::new("create").long("create")
1776 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1777 /// [`Arg::default_value`]: Arg::default_value()
1791 /// See [`Arg::default_missing_value`].
1793 /// [`Arg::default_missing_value`]: Arg::default_missing_value()
1803 /// See [`Arg::default_missing_value`].
1805 /// [`Arg::default_missing_value`]: Arg::default_missing_value()
1814 /// See [`Arg::default_missing_values`].
1816 /// [`Arg::default_missing_values`]: Arg::default_missing_values()
1834 /// - When [`Arg::action(ArgAction::Set)`] is not set, the flag is considered raised.
1835 /// - When [`Arg::action(ArgAction::Set)`] is set,
1840 /// - When [`Arg::action(ArgAction::Set)`] is not set, the flag is considered off.
1841 /// - When [`Arg::action(ArgAction::Set)`] is set,
1851 /// # use clap::{Command, Arg, ArgAction};
1856 /// .arg(Arg::new("flag")
1877 /// # use clap::{Command, Arg, ArgAction};
1884 /// .arg(Arg::new("true_flag")
1889 /// .arg(Arg::new("false_flag")
1894 /// .arg(Arg::new("absent_flag")
1912 /// # use clap::{Command, Arg, ArgAction};
1917 /// .arg(Arg::new("flag")
1933 /// # use clap::{Command, Arg, ArgAction};
1938 /// .arg(Arg::new("flag")
1954 /// # use clap::{Command, Arg, ArgAction};
1959 /// .arg(Arg::new("flag")
1971 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
1972 /// [`Arg::value_delimiter(',')`]: Arg::value_delimiter()
1990 deprecated(since = "4.0.0", note = "Replaced with `Arg::env`")
1998 impl Arg {
2003 /// If [`Arg::long_help`] is not specified, this message will be displayed for `--help`.
2005 /// **NOTE:** Only `Arg::help` is used in completion script generation in order to be concise
2018 /// # use clap::{Command, Arg};
2020 /// .arg(Arg::new("cfg")
2040 /// [`Arg::long_help`]: Arg::long_help()
2053 /// If [`Arg::help`] is not specified, this message will be displayed for `-h`.
2055 /// **NOTE:** Only [`Arg::help`] is used in completion script generation in order to be concise
2068 /// # use clap::{Command, Arg};
2070 /// .arg(Arg::new("cfg")
2102 /// [`Arg::help`]: Arg::help()
2126 /// # use clap::{Command, Arg, ArgAction};
2128 /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name.
2135 /// .arg(Arg::new("b")
2162 /// [positional arguments]: Arg::index()
2163 /// [index]: Arg::index()
2181 /// Render the [help][Arg::help] on the line after the argument.
2193 /// # use clap::{Command, Arg, ArgAction};
2195 /// .arg(Arg::new("opt")
2244 /// # use clap::{Command, Arg};
2246 /// .arg(Arg::new("cfg")
2281 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
2289 /// # use clap::{Command, Arg, ArgAction};
2291 /// .arg(Arg::new("mode")
2313 /// **NOTE:** Setting this requires [taking values][Arg::num_args]
2318 /// # use clap::{Command, Arg, ArgAction};
2320 /// .arg(Arg::new("host")
2347 /// # use clap::{Command, Arg, ArgAction};
2349 /// .arg(Arg::new("mode")
2376 /// # use clap::{Command, Arg, ArgAction};
2378 /// .arg(Arg::new("host")
2409 /// # use clap::{Command, Arg};
2410 /// Arg::new("debug")
2418 /// # use clap::{Command, Arg};
2420 /// .arg(Arg::new("cfg")
2445 /// # use clap::{Command, Arg};
2447 /// .arg(Arg::new("cfg")
2491 /// # use clap::{Command, Arg};
2493 /// .arg(Arg::new("cfg")
2518 /// # use clap::{Command, Arg};
2520 /// .arg(Arg::new("cfg")
2553 impl Arg {
2559 /// # use clap::{Command, Arg, ArgAction};
2560 /// Arg::new("debug")
2571 /// # use clap::{Command, Arg, ArgAction};
2573 /// .arg(Arg::new("debug")
2577 /// .arg(Arg::new("verbose")
2603 /// # use clap::{Command, Arg, ArgAction};
2604 /// Arg::new("debug")
2615 /// # use clap::{Command, Arg, ArgAction};
2617 /// .arg(Arg::new("debug")
2621 /// .arg(Arg::new("verbose")
2643 /// **NOTE:** This setting is perfectly compatible with [`Arg::default_value`] but slightly
2644 /// different. `Arg::default_value` *only* takes effect when the user has not provided this arg
2646 /// runtime **and** these other conditions are met as well. If you have set `Arg::default_value`
2647 /// and `Arg::default_value_if`, and the user **did not** provide this arg at runtime, nor were
2648 /// the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be applied.
2650 /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`].
2657 /// # use clap::{Command, Arg, ArgAction};
2660 /// .arg(Arg::new("flag")
2663 /// .arg(Arg::new("other")
2676 /// # use clap::{Command, Arg, ArgAction};
2678 /// .arg(Arg::new("flag")
2681 /// .arg(Arg::new("other")
2694 /// # use clap::{Command, Arg, ArgAction};
2696 /// .arg(Arg::new("opt")
2699 /// .arg(Arg::new("other")
2713 /// # use clap::{Command, Arg, ArgAction};
2715 /// .arg(Arg::new("opt")
2718 /// .arg(Arg::new("other")
2728 /// If we want to unset the default value for an Arg based on the presence or
2729 /// value of some other Arg.
2732 /// # use clap::{Command, Arg, ArgAction};
2734 /// .arg(Arg::new("flag")
2737 /// .arg(Arg::new("other")
2747 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
2748 /// [`Arg::default_value`]: Arg::default_value()
2768 deprecated(since = "4.0.0", note = "Replaced with `Arg::default_value_if`")
2779 /// Specifies multiple values and conditions in the same manner as [`Arg::default_value_if`].
2791 /// # use clap::{Command, Arg, ArgAction};
2793 /// .arg(Arg::new("flag")
2796 /// .arg(Arg::new("opt")
2799 /// .arg(Arg::new("other")
2815 /// # use clap::{Command, Arg, ArgAction};
2817 /// .arg(Arg::new("flag")
2820 /// .arg(Arg::new("other")
2837 /// # use clap::{Command, Arg, ArgAction};
2840 /// .arg(Arg::new("flag")
2843 /// .arg(Arg::new("opt")
2846 /// .arg(Arg::new("other")
2858 /// [`Arg::action(ArgAction::Set)`]: Arg::action()
2859 /// [`Arg::default_value_if`]: Arg::default_value_if()
2881 deprecated(since = "4.0.0", note = "Replaced with `Arg::default_value_ifs`")
2898 /// **Pro Tip:** Using `Arg::required_unless_present` implies [`Arg::required`] and is therefore not
2904 /// # use clap::Arg;
2905 /// Arg::new("config")
2914 /// # use clap::{Command, Arg, ArgAction};
2916 /// .arg(Arg::new("cfg")
2920 /// .arg(Arg::new("dbg")
2930 /// Setting `Arg::required_unless_present(name)` and *not* supplying `name` or this arg is an error.
2933 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
2935 /// .arg(Arg::new("cfg")
2939 /// .arg(Arg::new("dbg")
2948 /// [required]: Arg::required()
2966 /// present see [`Arg::required_unless_present_any`]
2971 /// # use clap::Arg;
2972 /// Arg::new("config")
2981 /// # use clap::{Command, Arg, ArgAction};
2983 /// .arg(Arg::new("cfg")
2987 /// .arg(Arg::new("dbg")
2990 /// .arg(Arg::new("infile")
3000 /// Setting [`Arg::required_unless_present_all(names)`] and *not* supplying
3004 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3006 /// .arg(Arg::new("cfg")
3010 /// .arg(Arg::new("dbg")
3013 /// .arg(Arg::new("infile")
3023 /// [required]: Arg::required()
3024 /// [`Arg::required_unless_present_any`]: Arg::required_unless_present_any()
3025 /// [`Arg::required_unless_present_all(names)`]: Arg::required_unless_present_all()
3042 /// present see [`Arg::required_unless_present_all`]
3047 /// # use clap::Arg;
3048 /// Arg::new("config")
3053 /// Setting [`Arg::required_unless_present_any(names)`] requires that the argument be used at runtime
3059 /// # use clap::{Command, Arg, ArgAction};
3061 /// .arg(Arg::new("cfg")
3065 /// .arg(Arg::new("dbg")
3068 /// .arg(Arg::new("infile")
3078 /// Setting [`Arg::required_unless_present_any(names)`] and *not* supplying *at least one of* `names`
3082 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3084 /// .arg(Arg::new("cfg")
3088 /// .arg(Arg::new("dbg")
3091 /// .arg(Arg::new("infile")
3101 /// [required]: Arg::required()
3102 /// [`Arg::required_unless_present_any(names)`]: Arg::required_unless_present_any()
3103 /// [`Arg::required_unless_present_all`]: Arg::required_unless_present_all()
3119 /// # use clap::Arg;
3120 /// Arg::new("config")
3126 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3128 /// .arg(Arg::new("cfg")
3132 /// .arg(Arg::new("other")
3142 /// .arg(Arg::new("cfg")
3146 /// .arg(Arg::new("other")
3158 /// .arg(Arg::new("cfg")
3162 /// .arg(Arg::new("other")
3173 /// .arg(Arg::new("cfg")
3177 /// .arg(Arg::new("other")
3185 /// // However, case-insensitive comparisons can be enabled. This typically occurs when using Arg::possible_values().
3189 /// [`Arg::requires(name)`]: Arg::requires()
3190 /// [Conflicting]: Arg::conflicts_with()
3191 /// [required]: Arg::required()
3206 /// # use clap::Arg;
3207 /// Arg::new("config")
3215 /// Setting `Arg::required_if_eq_any([(arg, val)])` makes this arg required if any of the `arg`s
3220 /// # use clap::{Command, Arg, ArgAction};
3222 /// .arg(Arg::new("cfg")
3229 /// .arg(Arg::new("extra")
3232 /// .arg(Arg::new("option")
3242 /// Setting `Arg::required_if_eq_any([(arg, val)])` and having any of the `arg`s used with its
3246 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3248 /// .arg(Arg::new("cfg")
3255 /// .arg(Arg::new("extra")
3258 /// .arg(Arg::new("option")
3268 /// [`Arg::requires(name)`]: Arg::requires()
3269 /// [Conflicting]: Arg::conflicts_with()
3270 /// [required]: Arg::required()
3289 /// # use clap::Arg;
3290 /// Arg::new("config")
3298 /// Setting `Arg::required_if_eq_all([(arg, val)])` makes this arg required if all of the `arg`s
3303 /// # use clap::{Command, Arg, ArgAction};
3305 /// .arg(Arg::new("cfg")
3312 /// .arg(Arg::new("extra")
3315 /// .arg(Arg::new("option")
3325 /// Setting `Arg::required_if_eq_all([(arg, val)])` and having all of the `arg`s used with its
3329 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3331 /// .arg(Arg::new("cfg")
3338 /// .arg(Arg::new("extra")
3341 /// .arg(Arg::new("option")
3351 /// [required]: Arg::required()
3371 /// # use clap::Arg;
3372 /// Arg::new("config")
3377 /// Setting `Arg::requires_if(val, arg)` requires that the `arg` be used at runtime if the
3382 /// # use clap::{Command, Arg, ArgAction};
3384 /// .arg(Arg::new("cfg")
3388 /// .arg(Arg::new("other"))
3396 /// Setting `Arg::requires_if(val, arg)` and setting the value to `val` but *not* supplying
3400 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3402 /// .arg(Arg::new("cfg")
3406 /// .arg(Arg::new("input"))
3414 /// [`Arg::requires(name)`]: Arg::requires()
3415 /// [Conflicting]: Arg::conflicts_with()
3416 /// [override]: Arg::overrides_with()
3431 /// # use clap::Arg;
3432 /// Arg::new("config")
3440 /// Setting `Arg::requires_ifs(["val", "arg"])` requires that the `arg` be used at runtime if the
3445 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3447 /// .arg(Arg::new("cfg")
3454 /// .arg(Arg::new("opt")
3457 /// .arg(Arg::new("other"))
3466 /// Setting `Arg::requires_ifs` with [`ArgPredicate::IsPresent`] and *not* supplying all the
3470 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction, builder::ArgPredicate};
3472 /// .arg(Arg::new("cfg")
3479 /// .arg(Arg::new("input"))
3480 /// .arg(Arg::new("output"))
3490 /// [`Arg::requires(name)`]: Arg::requires()
3491 /// [Conflicting]: Arg::conflicts_with()
3492 /// [override]: Arg::overrides_with()
3506 deprecated(since = "4.0.0", note = "Replaced with `Arg::requires_ifs`")
3521 /// **NOTE:** [`Arg::conflicts_with_all(names)`] allows specifying an argument which conflicts with more than one argument.
3523 /// **NOTE** [`Arg::exclusive(true)`] allows specifying an argument which conflicts with every other argument.
3530 /// # use clap::Arg;
3531 /// Arg::new("config")
3539 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3541 /// .arg(Arg::new("cfg")
3545 /// .arg(Arg::new("debug")
3556 /// [`Arg::conflicts_with_all(names)`]: Arg::conflicts_with_all()
3557 /// [`Arg::exclusive(true)`]: Arg::exclusive()
3570 /// See [`Arg::conflicts_with`].
3579 /// **NOTE:** [`Arg::exclusive(true)`] allows specifying an argument which conflicts with every other argument.
3584 /// # use clap::Arg;
3585 /// Arg::new("config")
3594 /// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
3596 /// .arg(Arg::new("cfg")
3600 /// .arg(Arg::new("debug")
3602 /// .arg(Arg::new("input"))
3610 /// [`Arg::conflicts_with`]: Arg::conflicts_with()
3611 /// [`Arg::exclusive(true)`]: Arg::exclusive()
3627 /// **NOTE:** Overriding an argument implies they [conflict][Arg::conflicts_with`].
3666 /// **NOTE:** Overriding an argument implies they [conflict][Arg::conflicts_with_all`].
3696 impl Arg {
3714 /// # use clap::Arg;
3715 /// let arg = Arg::new("foo").long_help("long help");
3897 /// # use clap::Arg;
3898 /// let arg = Arg::new("foo").env("ENVIRONMENT");
3911 /// # use clap::Arg;
3912 /// let arg = Arg::new("foo").default_value("default value");
3924 /// # use clap::Arg;
3925 /// let arg = Arg::new("foo");
3928 /// let arg = Arg::new("foo").long("foo");
3935 /// Reports whether [`Arg::required`] is set
3948 /// Report whether [`Arg::allow_hyphen_values`] is set
3953 /// Report whether [`Arg::allow_negative_numbers`] is set
3971 /// clap::Arg::new("port")
3988 /// Report whether [`Arg::global`] is set
3993 /// Report whether [`Arg::next_line_help`] is set
3998 /// Report whether [`Arg::hide`] is set
4003 /// Report whether [`Arg::hide_default_value`] is set
4008 /// Report whether [`Arg::hide_possible_values`] is set
4013 /// Report whether [`Arg::hide_env`] is set
4019 /// Report whether [`Arg::hide_env_values`] is set
4025 /// Report whether [`Arg::hide_short_help`] is set
4030 /// Report whether [`Arg::hide_long_help`] is set
4035 /// Report whether [`Arg::require_equals`] is set
4040 /// Reports whether [`Arg::exclusive`] is set
4045 /// Report whether [`Arg::trailing_var_arg`] is set
4050 /// Reports whether [`Arg::last`] is set
4055 /// Reports whether [`Arg::ignore_case`] is set
4062 impl Arg {
4118 debug!("Arg::name_no_brackets:{}", self.get_id());
4121 debug!("Arg::name_no_brackets: val_names={:#?}", self.val_names);
4137 debug!("Arg::name_no_brackets: just name");
4244 impl From<&'_ Arg> for Arg {
4245 fn from(a: &Arg) -> Self {
4250 impl PartialEq for Arg {
4251 fn eq(&self, other: &Arg) -> bool {
4256 impl PartialOrd for Arg {
4262 impl Ord for Arg {
4263 fn cmp(&self, other: &Arg) -> Ordering {
4268 impl Eq for Arg {}
4270 impl Display for Arg {
4276 impl fmt::Debug for Arg {
4278 let mut ds = f.debug_struct("Arg");
4322 use super::Arg;
4327 let mut f = Arg::new("flg").long("flag").action(ArgAction::SetTrue);
4335 let mut f2 = Arg::new("flg").short('f').action(ArgAction::SetTrue);
4343 let mut f2 = Arg::new("flg").long("flag").action(ArgAction::Count);
4351 let mut f = Arg::new("flg")
4362 let mut f = Arg::new("flg").short('f').action(ArgAction::SetTrue);
4376 let mut f = Arg::new("flg").short('a').action(ArgAction::SetTrue);
4385 let mut f = Arg::new("flg").short('a').action(ArgAction::SetTrue);
4396 let mut o = Arg::new("opt").long("option").action(ArgAction::Append);
4404 let mut o = Arg::new("opt")
4415 let mut o = Arg::new("opt")
4426 let mut o = Arg::new("opt")
4437 let mut o = Arg::new("opt")
4449 let mut o = Arg::new("opt")
4461 let mut o = Arg::new("opt")
4472 let mut o = Arg::new("opt")
4483 let mut o = Arg::new("opt")
4495 let mut o = Arg::new("opt")
4506 let mut o = Arg::new("opt")
4518 let mut o = Arg::new("opt")
4529 let mut o = Arg::new("opt")
4543 let mut p = Arg::new("pos").index(1).num_args(1..);
4551 let mut p = Arg::new("pos").index(1).num_args(1..).required(true);
4559 let mut p = Arg::new("pos").index(1).num_args(0..);
4567 let mut p = Arg::new("pos").index(1).num_args(1..);
4575 let mut p = Arg::new("pos").index(1).num_args(1..).required(true);
4583 let mut p = Arg::new("pos")
4594 let mut p = Arg::new("pos").index(1).action(ArgAction::Append);
4602 let mut p = Arg::new("pos")
4613 let mut p = Arg::new("pos").index(1).required(true);
4621 let mut p = Arg::new("pos").index(1).value_names(["file1", "file2"]);
4629 let mut p = Arg::new("pos")
4640 let mut p = Arg::new("pos")