Struct Arg
struct Arg { ... }
The abstract representation of a command line argument. Used to set all the options and relationships that define a valid argument for the program.
There are two methods for constructing Args, using the builder pattern and setting options
manually, or using a usage string which is far less verbose but has fewer options. You can also
use a combination of the two methods to achieve the best of both worlds.
- [Basic API][crate::Arg#basic-api]
- [Value Handling][crate::Arg#value-handling]
- [Help][crate::Arg#help-1]
- [Advanced Argument Relations][crate::Arg#advanced-argument-relations]
- [Reflection][crate::Arg#reflection]
Examples
# use clap_builder as clap;
# use ;
// Using the traditional builder pattern and setting each option manually
let cfg = new
.short
.long
.action
.value_name
.help;
// Using a usage string (setting a similar argument to the one above)
let input = arg!;
Implementations
impl Arg
fn group<impl IntoResettable<Id>: IntoResettable<Id>>(self: Self, group_id: impl IntoResettable<Id>) -> SelfThe name of the
ArgGroupthe argument belongs to.Examples
# use clap_builder as clap; # use ; new .long .action .group # ;Multiple arguments can be a member of a single group and then the group checked as if it was one of said arguments.
# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert!;fn groups<impl Into<Id>: Into<Id>, impl IntoIterator<Item = impl Into<Id>>: IntoIterator<Item = impl Into<Id>>>(self: Self, group_ids: impl IntoIterator<Item = impl Into<Id>>) -> SelfThe names of
ArgGroup's the argument belongs to.Examples
# use clap_builder as clap; # use ; new .long .action .groups # ;Arguments can be members of multiple groups and then the group checked as if it was one of said arguments.
# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert!; assert!;fn default_value_if<impl Into<Id>: Into<Id>, impl Into<ArgPredicate>: Into<ArgPredicate>, impl IntoResettable<OsStr>: IntoResettable<OsStr>>(self: Self, arg_id: impl Into<Id>, predicate: impl Into<ArgPredicate>, default: impl IntoResettable<OsStr>) -> SelfSpecifies the value of the argument if
arghas been used at runtime.If
defaultis set toNone,default_valuewill be removed.Like with command-line values, this will be split by
Arg::value_delimiter.NOTE: This setting is perfectly compatible with
Arg::default_valuebut slightly different.Arg::default_valueonly takes effect when the user has not provided this arg at runtime. This setting however only takes effect when the user has not provided a value at runtime and these other conditions are met as well. If you have setArg::default_valueandArg::default_value_if, and the user did not provide this arg at runtime, nor were the conditions met forArg::default_value_if, theArg::default_valuewill be applied.Examples
First we use the default value only if another arg is present at runtime.
# use clap_builder as clap; # use ; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;Next we run the same test, but without providing
--flag.# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;Now lets only use the default value if
--optcontains the valuespecial.# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;We can run the same test and provide any value other than
specialand we won't get a default value.# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;If we want to unset the default value for an Arg based on the presence or value of some other Arg.
# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;fn default_value_ifs<impl Into<Id>: Into<Id>, impl Into<ArgPredicate>: Into<ArgPredicate>, impl IntoResettable<OsStr>: IntoResettable<OsStr>, impl IntoIterator<Item = (impl Into<Id>, impl Into<ArgPredicate>, impl IntoResettable<OsStr>)>: IntoIterator<Item = (impl Into<Id>, impl Into<ArgPredicate>, impl IntoResettable<OsStr>)>>(self: Self, ifs: impl IntoIterator<Item = (impl Into<Id>, impl Into<ArgPredicate>, impl IntoResettable<OsStr>)>) -> SelfSpecifies multiple values and conditions in the same manner as
Arg::default_value_if.The method takes a slice of tuples in the
(arg, predicate, default)format.Like with command-line values, this will be split by
Arg::value_delimiter.NOTE: The conditions are stored in order and evaluated in the same order. I.e. the first if multiple conditions are true, the first one found will be applied and the ultimate value.
Examples
First we use the default value only if another arg is present at runtime.
# use clap_builder as clap; # use ; let m = new .arg .arg .arg .get_matches_from; assert_eq!;Next we run the same test, but without providing
--flag.# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert_eq!;We can also see that these values are applied in order, and if more than one condition is true, only the first evaluated "wins"
# use clap_builder as clap; # use ; # use ArgPredicate; let m = new .arg .arg .arg .get_matches_from; assert_eq!;fn required_unless_present<impl IntoResettable<Id>: IntoResettable<Id>>(self: Self, arg_id: impl IntoResettable<Id>) -> SelfSet this arg as required as long as the specified argument is not present at runtime.
TIP: Using
Arg::required_unless_presentimpliesArg::requiredand is therefore not mandatory to also set.Examples
# use clap_builder as clap; # use Arg; new .required_unless_present # ;In the following example, the required argument is not provided, but it's not an error because the
unlessarg has been supplied.# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!;Setting
Arg::required_unless_present(name)and not supplyingnameor this arg is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; assert_eq!;fn required_unless_present_all<impl Into<Id>: Into<Id>, impl IntoIterator<Item = impl Into<Id>>: IntoIterator<Item = impl Into<Id>>>(self: Self, names: impl IntoIterator<Item = impl Into<Id>>) -> SelfSets this arg as required unless all of the specified arguments are present at runtime.
In other words, parsing will succeed only if user either
- supplies the
selfarg. - supplies all of the
namesarguments.
NOTE: If you wish for this argument to only be required unless any of these args are present see
Arg::required_unless_present_anyExamples
# use clap_builder as clap; # use Arg; new .required_unless_present_all # ;In the following example, the required argument is not provided, but it's not an error because all of the
namesargs have been supplied.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!;Setting
Arg::required_unless_present_all(names)and not supplying either all ofunlessargs or theselfarg is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;- supplies the
fn required_unless_present_any<impl Into<Id>: Into<Id>, impl IntoIterator<Item = impl Into<Id>>: IntoIterator<Item = impl Into<Id>>>(self: Self, names: impl IntoIterator<Item = impl Into<Id>>) -> SelfSets this arg as required unless any of the specified arguments are present at runtime.
In other words, parsing will succeed only if user either
- supplies the
selfarg. - supplies one or more of the
unlessarguments.
NOTE: If you wish for this argument to be required unless all of these args are present see
Arg::required_unless_present_allExamples
# use clap_builder as clap; # use Arg; new .required_unless_present_any # ;Setting
Arg::required_unless_present_any(names)requires that the argument be used at runtime unless at least one of the args innamesare present. In the following example, the required argument is not provided, but it's not an error because one theunlessargs have been supplied.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!;Setting
Arg::required_unless_present_any(names)and not supplying at least one ofnamesor this arg is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;- supplies the
fn required_if_eq<impl Into<Id>: Into<Id>, impl Into<OsStr>: Into<OsStr>>(self: Self, arg_id: impl Into<Id>, val: impl Into<OsStr>) -> SelfThis argument is required only if the specified
argis present at runtime and its value equalsval.Examples
# use clap_builder as clap; # use Arg; new .required_if_eq # ;# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; // We didn't use --other=special, so "cfg" wasn't required let res = new .arg .arg .try_get_matches_from; // We did use --other=special so "cfg" had become required but was missing. assert!; assert_eq!; let res = new .arg .arg .try_get_matches_from; // By default, the comparison is case-sensitive, so "cfg" wasn't required assert!; let res = new .arg .arg .try_get_matches_from; // However, case-insensitive comparisons can be enabled. This typically occurs when using Arg::possible_values(). assert!; assert_eq!;fn required_if_eq_any<impl Into<Id>: Into<Id>, impl Into<OsStr>: Into<OsStr>, impl IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>: IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>>(self: Self, ifs: impl IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>) -> SelfSpecify this argument is required based on multiple conditions.
The conditions are set up in a
(arg, val)style tuple. The requirement will only become valid if one of the specifiedarg's value equals its correspondingval.Examples
# use clap_builder as clap; # use Arg; new .required_if_eq_any # ;Setting
Arg::required_if_eq_any([(arg, val)])makes this arg required if any of theargs are used at runtime and it's corresponding value is equal toval. If thearg's value is anything other thanval, this argument isn't required.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; // We didn't use --option=spec, or --extra=val so "cfg" isn't requiredSetting
Arg::required_if_eq_any([(arg, val)])and having any of theargs used with its value ofvalbut not using this arg is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;fn required_if_eq_all<impl Into<Id>: Into<Id>, impl Into<OsStr>: Into<OsStr>, impl IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>: IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>>(self: Self, ifs: impl IntoIterator<Item = (impl Into<Id>, impl Into<OsStr>)>) -> SelfSpecify this argument is required based on multiple conditions.
The conditions are set up in a
(arg, val)style tuple. The requirement will only become valid if every one of the specifiedarg's value equals its correspondingval.Examples
# use clap_builder as clap; # use Arg; new .required_if_eq_all # ;Setting
Arg::required_if_eq_all([(arg, val)])makes this arg required if all of theargs are used at runtime and every value is equal to its correspondingval. If thearg's value is anything other thanval, this argument isn't required.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; // We didn't use --option=spec --extra=val so "cfg" isn't requiredSetting
Arg::required_if_eq_all([(arg, val)])and having all of theargs used with its value ofvalbut not using this arg is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;fn requires_if<impl Into<ArgPredicate>: Into<ArgPredicate>, impl Into<Id>: Into<Id>>(self: Self, val: impl Into<ArgPredicate>, arg_id: impl Into<Id>) -> SelfRequire another argument if this arg matches the
ArgPredicateThis method takes
value, another_argpair. At runtime, clap will check if this arg (self) matches theArgPredicate. If it does,another_argwill be marked as required.Examples
# use clap_builder as clap; # use Arg; new .requires_if # ;Setting
Arg::requires_if(val, arg)requires that theargbe used at runtime if the defining argument's value is equal toval. If the defining argument is anything other thanval, the other argument isn't required.# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; // We didn't use --config=my.cfg, so other wasn't requiredSetting
Arg::requires_if(val, arg)and setting the value tovalbut not supplyingargis an error.# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; assert_eq!;fn requires_ifs<impl Into<ArgPredicate>: Into<ArgPredicate>, impl Into<Id>: Into<Id>, impl IntoIterator<Item = (impl Into<ArgPredicate>, impl Into<Id>)>: IntoIterator<Item = (impl Into<ArgPredicate>, impl Into<Id>)>>(self: Self, ifs: impl IntoIterator<Item = (impl Into<ArgPredicate>, impl Into<Id>)>) -> SelfAllows multiple conditional requirements.
The requirement will only become valid if this arg's value matches the
ArgPredicate.Examples
# use clap_builder as clap; # use Arg; new .requires_ifs # ;Setting
Arg::requires_ifs(["val", "arg"])requires that theargbe used at runtime if the defining argument's value is equal toval. If the defining argument's value is anything other thanval,argisn't required.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; // We used --config=special.conf so --option <val> is required assert_eq!;Setting
Arg::requires_ifswithArgPredicate::IsPresentand not supplying all the arguments is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; // We didn't use output assert_eq!;fn conflicts_with<impl IntoResettable<Id>: IntoResettable<Id>>(self: Self, arg_id: impl IntoResettable<Id>) -> SelfThis argument is mutually exclusive with the specified argument.
NOTE: Conflicting rules take precedence over being required by default. Conflict rules only need to be set for one of the two arguments, they do not need to be set for each.
NOTE: Defining a conflict is two-way, but does not need to defined for both arguments (i.e. if A conflicts with B, defining
A.conflicts_with(B)is sufficient. You do not need to also doB.conflicts_with(A))NOTE:
Arg::conflicts_with_all(names)allows specifying an argument which conflicts with more than one argument.NOTE
Arg::exclusive(true)allows specifying an argument which conflicts with every other argument.NOTE: All arguments implicitly conflict with themselves.
Examples
# use clap_builder as clap; # use Arg; new .conflicts_with # ;Setting conflicting argument, and having both arguments present at runtime is an error.
# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; assert_eq!;fn conflicts_with_all<impl Into<Id>: Into<Id>, impl IntoIterator<Item = impl Into<Id>>: IntoIterator<Item = impl Into<Id>>>(self: Self, names: impl IntoIterator<Item = impl Into<Id>>) -> SelfThis argument is mutually exclusive with the specified arguments.
See
Arg::conflicts_with.NOTE: Conflicting rules take precedence over being required by default. Conflict rules only need to be set for one of the two arguments, they do not need to be set for each.
NOTE: Defining a conflict is two-way, but does not need to defined for both arguments (i.e. if A conflicts with B, defining
A.conflicts_with(B)is sufficient. You do not need need to also doB.conflicts_with(A))NOTE:
Arg::exclusive(true)allows specifying an argument which conflicts with every other argument.Examples
# use clap_builder as clap; # use Arg; new .conflicts_with_all # ;Setting conflicting argument, and having any of the arguments present at runtime with a conflicting argument is an error.
# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;fn overrides_with<impl IntoResettable<Id>: IntoResettable<Id>>(self: Self, arg_id: impl IntoResettable<Id>) -> SelfSets an overridable argument.
i.e. this argument and the following argument will override each other in POSIX style (whichever argument was specified at runtime last "wins")
NOTE: When an argument is overridden it is essentially as if it never was used, any conflicts, requirements, etc. are evaluated after all "overrides" have been removed
NOTE: Overriding an argument implies they [conflict][Arg::conflicts_with`].
Examples
# use clap_builder as clap; # use ; let m = new .arg .arg .arg .get_matches_from; // ^~~~~~~~~~~~^~~~~ flag is overridden by color assert!; assert!; // even though flag conflicts with debug, it's as if flag // was never used because it was overridden with color assert!;fn overrides_with_all<impl Into<Id>: Into<Id>, impl IntoIterator<Item = impl Into<Id>>: IntoIterator<Item = impl Into<Id>>>(self: Self, names: impl IntoIterator<Item = impl Into<Id>>) -> SelfSets multiple mutually overridable arguments by name.
i.e. this argument and the following argument will override each other in POSIX style (whichever argument was specified at runtime last "wins")
NOTE: When an argument is overridden it is essentially as if it never was used, any conflicts, requirements, etc. are evaluated after all "overrides" have been removed
NOTE: Overriding an argument implies they [conflict][Arg::conflicts_with_all`].
Examples
# use clap_builder as clap; # use ; let m = new .arg .arg .arg .get_matches_from; // ^~~~~~^~~~~~~~~ flag and debug are overridden by color assert!; // even though flag conflicts with color, it's as if flag // and debug were never used because they were overridden // with color assert!; assert!;
impl Arg
fn help<impl IntoResettable<StyledStr>: IntoResettable<StyledStr>>(self: Self, h: impl IntoResettable<StyledStr>) -> SelfSets the description of the argument for short help (
-h).Typically, this is a short (one line) description of the arg.
If
Arg::long_helpis not specified, this message will be displayed for--help.NOTE: Only
Arg::helpis used in completion script generation in order to be conciseExamples
Any valid UTF-8 is allowed in the help text. The one exception is when one wishes to include a newline in the help text and have the following text be properly aligned with all the other help text.
Setting
helpdisplays a short message to the side of the argument when the user passes-hor--help(by default).#The above example displays
helptest Usage: helptest [OPTIONS] Options: --config Some help text describing the --config arg -h, --help Print help information -V, --version Print version informationfn long_help<impl IntoResettable<StyledStr>: IntoResettable<StyledStr>>(self: Self, h: impl IntoResettable<StyledStr>) -> SelfSets the description of the argument for long help (
--help).Typically this a more detailed (multi-line) message that describes the arg.
If
Arg::helpis not specified, this message will be displayed for-h.NOTE: Only
Arg::helpis used in completion script generation in order to be conciseExamples
Any valid UTF-8 is allowed in the help text. The one exception is when one wishes to include a newline in the help text and have the following text be properly aligned with all the other help text.
Setting
helpdisplays a short message to the side of the argument when the user passes-hor--help(by default).#The above example displays
prog Usage: prog [OPTIONS] Options: --config 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. -h, --help Print help information -V, --version Print version informationfn display_order<impl IntoResettable<usize>: IntoResettable<usize>>(self: Self, ord: impl IntoResettable<usize>) -> SelfAllows custom ordering of args within the help message.
Args with a lower value will be displayed first in the help message. Those with the same display order will be sorted.Args are automatically assigned a display order based on the order they are added to the [Command][crate::Command]. Overriding this is helpful when the order arguments are added in isn't the same as the display order, whether in one-off cases or to automatically sort arguments.To change, see [
Command::next_display_order][crate::Command::next_display_order].NOTE: This setting is ignored for positional arguments which are always displayed in index order.
Examples
#The above example displays the following help message
cust-ord Usage: cust-ord [OPTIONS] Options: -a, --airplane <airplane> I should be first! -b, --boat <boar> Some help and text -h, --help Print help information -? Alt helpfn help_heading<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, heading: impl IntoResettable<Str>) -> SelfOverride the current help section.
fn next_line_help(self: Self, yes: bool) -> SelfRender the [help][Arg::help] on the line after the argument.
This can be helpful for arguments with very long or complex help messages. This can also be helpful for arguments with very long flag names, or many/long value names.
NOTE: To apply this setting to all arguments and subcommands, consider using
crate::Command::next_line_helpExamples
#The above example displays the following help message
nlh Usage: nlh [OPTIONS] Options: -h, --help Print help information -V, --version Print version information -o, --long-option-flag <value1> <value2> Some really long help and complex help that makes more sense to be on a line after the optionfn hide(self: Self, yes: bool) -> SelfDo not display the argument in help message.
NOTE: This does not hide the argument from usage strings on error
Examples
Setting
Hiddenwill hide the argument when displaying help text#The above example displays
helptest Usage: helptest [OPTIONS] Options: -h, --help Print help information -V, --version Print version informationfn hide_possible_values(self: Self, yes: bool) -> SelfDo not display the [possible values][crate::builder::ValueParser::possible_values] in the help message.
This is useful for args with many values, or ones which are explained elsewhere in the help text.
To set this for all arguments, see [
Command::hide_possible_values][crate::Command::hide_possible_values].NOTE: Setting this requires [taking values][Arg::num_args]
Examples
# use clap_builder as clap; # use ; let m = new .arg;If we were to run the above program with
--helpthe[values: fast, slow]portion of the help text would be omitted.fn hide_default_value(self: Self, yes: bool) -> SelfDo not display the default value of the argument in the help message.
This is useful when default behavior of an arg is explained elsewhere in the help text.
NOTE: Setting this requires [taking values][Arg::num_args]
Examples
# use clap_builder as clap; # use ; let m = new .arg;If we were to run the above program with
--helpthe[default: localhost]portion of the help text would be omitted.fn hide_short_help(self: Self, yes: bool) -> SelfHides an argument from short help (
-h).NOTE: This does not hide the argument from usage strings on error
NOTE: Setting this option will cause next-line-help output style to be used when long help (
--help) is called.Examples
# use clap_builder as clap; # use ; new .hide_short_help;Setting
hide_short_help(true)will hide the argument when displaying short help text#The above example displays
helptest Usage: helptest [OPTIONS] Options: -h, --help Print help information -V, --version Print version informationHowever, when --help is called
#Then the following would be displayed
helptest Usage: helptest [OPTIONS] Options: --config Some help text describing the --config arg -h, --help Print help information -V, --version Print version informationfn hide_long_help(self: Self, yes: bool) -> SelfHides an argument from long help (
--help).NOTE: This does not hide the argument from usage strings on error
NOTE: Setting this option will cause next-line-help output style to be used when long help (
--help) is called.Examples
Setting
hide_long_help(true)will hide the argument when displaying long help text#The above example displays
helptest Usage: helptest [OPTIONS] Options: -h, --help Print help information -V, --version Print version informationHowever, when -h is called
#Then the following would be displayed
helptest Usage: helptest [OPTIONS] OPTIONS: --config Some help text describing the --config arg -h, --help Print help information -V, --version Print version information
impl Arg
fn new<impl Into<Id>: Into<Id>>(id: impl Into<Id>) -> SelfCreate a new
Argwith a unique name.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::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.Examples
# use clap_builder as clap; # use ; new # ;fn id<impl Into<Id>: Into<Id>>(self: Self, id: impl Into<Id>) -> SelfSet the identifier used for referencing this argument in the clap API.
See
Arg::newfor more details.fn short<impl IntoResettable<char>: IntoResettable<char>>(self: Self, s: impl IntoResettable<char>) -> SelfSets the short version of the argument without the preceding
-.By default
Vandhare used by the auto-generatedversionandhelparguments, respectively. You will need to disable the auto-generated flags ([disable_help_flag][crate::Command::disable_help_flag], [disable_version_flag][crate::Command::disable_version_flag]) and define your own.Examples
When calling
short, use a single valid UTF-8 character which will allow using the argument via a single hyphen (-) such as-c:# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;To use
-hfor your own flag and still have help:# use clap_builder as clap; # use ; let m = new .disable_help_flag .arg .arg .get_matches_from; assert_eq!;fn long<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, l: impl IntoResettable<Str>) -> SelfSets the long version of the argument without the preceding
--.By default
versionandhelpare used by the auto-generatedversionandhelparguments, respectively. You may use the wordversionorhelpfor the long form of your own arguments, in which caseclapsimply will not assign those to the auto-generatedversionorhelparguments.NOTE: Any leading
-characters will be strippedExamples
To set
longuse a word containing valid UTF-8. If you supply a double leading--such as--configthey will be stripped. Hyphens in the middle of the word, however, will not be stripped (i.e.config-fileis allowed).Setting
longallows using the argument via a double hyphen (--) such as--config# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn alias<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, name: impl IntoResettable<Str>) -> SelfAdd an alias, which functions as a hidden long flag.
This is more efficient, and easier than creating multiple hidden arguments as one only needs to check for the existence of this command, and not all variants.
Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn short_alias<impl IntoResettable<char>: IntoResettable<char>>(self: Self, name: impl IntoResettable<char>) -> SelfAdd an alias, which functions as a hidden short flag.
This is more efficient, and easier than creating multiple hidden arguments as one only needs to check for the existence of this command, and not all variants.
Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn aliases<impl Into<Str>: Into<Str>, impl IntoIterator<Item = impl Into<Str>>: IntoIterator<Item = impl Into<Str>>>(self: Self, names: impl IntoIterator<Item = impl Into<Str>>) -> SelfAdd aliases, which function as hidden long flags.
This is more efficient, and easier than creating multiple hidden subcommands as one only needs to check for the existence of this command, and not all variants.
Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn short_aliases<impl IntoIterator<Item = char>: IntoIterator<Item = char>>(self: Self, names: impl IntoIterator<Item = char>) -> SelfAdd aliases, which functions as a hidden short flag.
This is more efficient, and easier than creating multiple hidden subcommands as one only needs to check for the existence of this command, and not all variants.
Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn visible_alias<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, name: impl IntoResettable<Str>) -> SelfAdd an alias, which functions as a visible long flag.
Like
Arg::alias, except that they are visible inside the help message.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn visible_short_alias<impl IntoResettable<char>: IntoResettable<char>>(self: Self, name: impl IntoResettable<char>) -> SelfAdd an alias, which functions as a visible short flag.
Like
Arg::short_alias, except that they are visible inside the help message.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn visible_aliases<impl Into<Str>: Into<Str>, impl IntoIterator<Item = impl Into<Str>>: IntoIterator<Item = impl Into<Str>>>(self: Self, names: impl IntoIterator<Item = impl Into<Str>>) -> SelfAdd aliases, which function as visible long flags.
Like
Arg::aliases, except that they are visible inside the help message.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn visible_short_aliases<impl IntoIterator<Item = char>: IntoIterator<Item = char>>(self: Self, names: impl IntoIterator<Item = char>) -> SelfAdd aliases, which function as visible short flags.
Like
Arg::short_aliases, except that they are visible inside the help message.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;fn index<impl IntoResettable<usize>: IntoResettable<usize>>(self: Self, idx: impl IntoResettable<usize>) -> SelfSpecifies the index of a positional argument starting at 1.
NOTE: The index refers to position according to other positional argument. It does not define position in the argument list as a whole.
NOTE: You can optionally leave off the
indexmethod, and the index will be assigned in order of evaluation. Utilizing theindexmethod allows for setting indexes out of orderNOTE: This is only meant to be used for positional arguments and shouldn't to be used with
Arg::shortorArg::long.NOTE: When utilized with [
Arg::num_args(1..)], only the last positional argument may be defined as having a variable number of arguments (i.e. with the highest index)Panics
Commandwill [panic!] if indexes are skipped (such as definingindex(1)andindex(3)but notindex(2), or a positional argument is defined as multiple and is not the highest index (debug builds)Examples
# use clap_builder as clap; # use ; new .index # ;# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; assert!; assert_eq!; // notice index(1) means "first positional" // *not* first argumentfn trailing_var_arg(self: Self, yes: bool) -> SelfThis is a "var arg" and everything that follows should be captured by it, as if the user had used a
--.NOTE: To start the trailing "var arg" on unknown flags (and not just a positional value), set [
allow_hyphen_values][Arg::allow_hyphen_values]. Either way, users still have the option to explicitly escape ambiguous arguments with--.NOTE:
Arg::value_delimiterstill applies if set.NOTE: Setting this requires
Arg::num_args(..).Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; let trail: = m..unwrap.collect; assert_eq!;fn last(self: Self, yes: bool) -> SelfThis arg is the last, or final, positional argument (i.e. has the highest index) and is only able to be accessed via the
--syntax (i.e.$ prog args -- last_arg).Even, if no other arguments are left to parse, if the user omits the
--syntax they will receive anUnknownArgumenterror. Setting an argument to.last(true)also allows one to access this arg early using the--syntax. Accessing an arg early, even with the--syntax is otherwise not possible.NOTE: This will change the usage string to look like
$ prog [OPTIONS] [-- <ARG>]ifARGis marked as.last(true).NOTE: This setting will imply
crate::Command::dont_collapse_args_in_usagebecause failing to set this can make the usage string very confusing.NOTE: This setting only applies to positional arguments, and has no effect on OPTIONS
NOTE: Setting this requires [taking values][Arg::num_args]
WARNING: Using this setting and having child subcommands is not recommended with the exception of also using
crate::Command::args_conflicts_with_subcommands(orcrate::Command::subcommand_negates_reqsif the argument markedLastis also markedArg::required)Examples
# use clap_builder as clap; # use ; new .action .last # ;Setting
lastensures the arg has the highest index of all positional args and requires that the--syntax be used to access it early.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; let m = res.unwrap; assert_eq!; assert_eq!;Even if the positional argument marked
Lastis the only argument left to parse, failing to use the--syntax results in an error.# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;fn required(self: Self, yes: bool) -> SelfSpecifies that the argument must be present.
Required by default means it is required, when no other conflicting rules or overrides have been evaluated. Conflicting rules take precedence over being required.
Pro tip: Flags (i.e. not positional, or arguments that take values) shouldn't be required by default. This is because if a flag were to be required, it should simply be implied. No additional information is required from user. Flags by their very nature are simply boolean on/off switches. The only time a user should be required to use a flag is if the operation is destructive in nature, and the user is essentially proving to you, "Yes, I know what I'm doing."
Examples
# use clap_builder as clap; # use Arg; new .required # ;Setting required requires that the argument be used at runtime.
# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!;Setting required and then not supplying that argument at runtime is an error.
# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!; assert_eq!;fn requires<impl IntoResettable<Id>: IntoResettable<Id>>(self: Self, arg_id: impl IntoResettable<Id>) -> SelfSets an argument that is required when this one is present
i.e. when using this argument, the following argument must be present.
NOTE: Conflicting rules and override rules take precedence over being required
Examples
# use clap_builder as clap; # use Arg; new .requires # ;Setting
Arg::requires(name)requires that the argument be used at runtime if the defining argument is used. If the defining argument isn't used, the other argument isn't required# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; // We didn't use cfg, so input wasn't requiredSetting
Arg::requires(name)and not supplying that argument is an error.# use clap_builder as clap; # use ; let res = new .arg .arg .try_get_matches_from; assert!; assert_eq!;fn exclusive(self: Self, yes: bool) -> SelfThis argument must be passed alone; it conflicts with all other arguments.
Examples
# use clap_builder as clap; # use Arg; new .exclusive # ;Setting an exclusive argument and having any other arguments present at runtime is an error.
# use clap_builder as clap; # use ; let res = new .arg .arg .arg .try_get_matches_from; assert!; assert_eq!;fn global(self: Self, yes: bool) -> SelfSpecifies that an argument can be matched to all child
Subcommands.NOTE: Global arguments only propagate down, not up (to parent commands), however their values once a user uses them will be propagated back up to parents. In effect, this means one should define all global arguments at the top level, however it doesn't matter where the user uses the global argument.
Examples
Assume an application with two subcommands, and you'd like to define a
--verboseflag that can be called on any of the subcommands and parent, but you don't want to clutter the source with three duplicateArgdefinitions.# use clap_builder as clap; # use ; let m = new .arg .subcommand .subcommand .get_matches_from; assert_eq!; let sub_m = m.subcommand_matches.unwrap; assert_eq!;
impl Arg
fn action<impl IntoResettable<ArgAction>: IntoResettable<ArgAction>>(self: Self, action: impl IntoResettable<ArgAction>) -> SelfSpecify how to react to an argument when parsing it.
ArgActioncontrols things like- Overwriting previous values with new ones
- Appending new values to all previous ones
- Counting how many times a flag occurs
The default action is
ArgAction::SetExamples
# use clap_builder as clap; # use Command; # use Arg; let cmd = new .arg; let matches = cmd.try_get_matches_from.unwrap; assert!; assert_eq!;fn value_parser<impl IntoResettable<super::ValueParser>: IntoResettable<super::ValueParser>>(self: Self, parser: impl IntoResettable<super::ValueParser>) -> SelfSpecify the typed behavior of the argument.
This allows parsing and validating a value before storing it into [
ArgMatches][crate::ArgMatches] as the given type.Possible value parsers include:
- [
value_parser!(T)][crate::value_parser!] for auto-selecting a value parser for a given type- Or [range expressions like
0..=1][std::ops::RangeBounds] as a shorthand for [RangedI64ValueParser][crate::builder::RangedI64ValueParser]
- Or [range expressions like
Fn(&str) -> Result<T, E>[&str]and [PossibleValuesParser][crate::builder::PossibleValuesParser] for static enumerated values- [
BoolishValueParser][crate::builder::BoolishValueParser], and [FalseyValueParser][crate::builder::FalseyValueParser] for alternativeboolimplementations - [
NonEmptyStringValueParser][crate::builder::NonEmptyStringValueParser] for basic validation for strings - or any other [
TypedValueParser][crate::builder::TypedValueParser] implementation
The default value is [
ValueParser::string][crate::builder::ValueParser::string].# use clap_builder as clap; # use ArgAction; let mut cmd = new .arg .arg .arg; let m = cmd.try_get_matches_from_mut.unwrap; let color: &String = m.get_one .expect; assert_eq!; let hostname: &String = m.get_one .expect; assert_eq!; let port: u16 = *m.get_one .expect; assert_eq!;- [
fn num_args<impl IntoResettable<ValueRange>: IntoResettable<ValueRange>>(self: Self, qty: impl IntoResettable<ValueRange>) -> SelfSpecifies the number of arguments parsed per occurrence
For example, if you had a
-f <file>argument where you wanted exactly 3 'files' you would set.num_args(3), and this argument wouldn't be satisfied unless the user provided 3 and only 3 values.Users may specify values for arguments in any of the following methods
- Using a space such as
-o valueor--option value - Using an equals and no space such as
-o=valueor--option=value - Use a short and no space such as
-ovalue
WARNING:
Setting a variable number of values (e.g.
1..=10) for an argument without other details can be dangerous in some circumstances. Because multiple values are allowed,--option val1 val2 val3is perfectly valid. Be careful when designing a CLI where positional arguments or subcommands are also expected asclapwill continue parsing values until one of the following happens:- It reaches the maximum number of values
- It reaches a specific number of values
- It finds another flag or option (i.e. something that starts with a
-) - It reaches the
Arg::value_terminatorif set
Alternatively,
- Use a delimiter between values with
Arg::value_delimiter - Require a flag occurrence per value with
ArgAction::Append - Require positional arguments to appear after
--withArg::last
Examples
Option:
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;Flag/option hybrid (see also [
default_missing_value][Arg::default_missing_value])# use clap_builder as clap; # use ; let cmd = new .arg; let m = cmd.clone .get_matches_from; assert_eq!; let m = cmd.clone .get_matches_from; assert_eq!; let m = cmd.clone .get_matches_from; assert_eq!;Tuples
# use clap_builder as clap; # use ; let cmd = new .arg; let m = cmd.clone .get_matches_from; assert_eq!; let res = cmd.clone .try_get_matches_from; assert_eq!;A common mistake is to define an option which allows multiple values and a positional argument.
# use clap_builder as clap; # use ; let cmd = new .arg .arg; let m = cmd.clone.get_matches_from; let files: = m..unwrap.collect; assert_eq!; // wait...what?! assert!; // but we clearly used word! // but this works let m = cmd.clone.get_matches_from; let files: = m..unwrap.collect; assert_eq!; assert_eq!;The problem is
clapdoesn't know when to stop parsing values for "file".A solution for the example above is to limit how many values with a maximum, or specific number, or to say
ArgAction::Appendis ok, but multiple values are not.# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; let files: = m..unwrap.collect; assert_eq!; assert_eq!;- Using a space such as
fn value_name<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, name: impl IntoResettable<Str>) -> SelfPlaceholder for the argument's value in the help message / usage.
This name is cosmetic only; the name is not used to access arguments. This setting can be very helpful when describing the type of input the user should be 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::action(ArgAction::Set)Examples
# use clap_builder as clap; # use ; new .long .value_name # ;# use clap_builder as clap; #Running the above program produces the following output
valnames Usage: valnames [OPTIONS] Options: --config <FILE> Some help text -h, --help Print help information -V, --version Print version informationfn value_names<impl Into<Str>: Into<Str>, impl IntoIterator<Item = impl Into<Str>>: IntoIterator<Item = impl Into<Str>>>(self: Self, names: impl IntoIterator<Item = impl Into<Str>>) -> SelfPlaceholders for the argument's values in the help message / usage.
These names are cosmetic only, used for help and usage strings only. The names are not used to access arguments. The values of the arguments are accessed in numeric order (i.e. if you specify two names
oneandtwoonewill be the first matched value,twowill be the second).This setting can be very helpful when describing the type of input the user should be using, such as
FILE,INTERFACE, etc. Although not required, it's somewhat convention to use all capital letters for the value name.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::action(ArgAction::Set)andArg::num_args(1..).Examples
# use clap_builder as clap; # use ; new .short .value_names;# use clap_builder as clap; #Running the above program produces the following output
valnames Usage: valnames [OPTIONS] Options: -h, --help Print help information --io-files <INFILE> <OUTFILE> Some help text -V, --version Print version informationfn value_hint<impl IntoResettable<ValueHint>: IntoResettable<ValueHint>>(self: Self, value_hint: impl IntoResettable<ValueHint>) -> SelfProvide the shell a hint about how to complete this argument.
See
ValueHintfor more information.NOTE: implicitly sets [
Arg::action(ArgAction::Set)].For example, to take a username as argument:
# use clap_builder as clap; # use ; new .short .long .value_hint;To take a full command line and its arguments (for example, when writing a command wrapper):
# use clap_builder as clap; # use ; new .trailing_var_arg .arg;fn ignore_case(self: Self, yes: bool) -> SelfMatch values against [
PossibleValuesParser][crate::builder::PossibleValuesParser] without matching case.When other arguments are conditionally required based on the value of a case-insensitive argument, the equality check done by
Arg::required_if_eq,Arg::required_if_eq_any, orArg::required_if_eq_allis case-insensitive.NOTE: Setting this requires [taking values][Arg::num_args]
NOTE: To do unicode case folding, enable the
unicodefeature flag.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert!;This setting also works when multiple values can be defined:
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; let matched_vals = m..unwrap.; assert_eq!;fn allow_hyphen_values(self: Self, yes: bool) -> SelfAllows values which start with a leading hyphen (
-)To limit values to just numbers, see [
allow_negative_numbers][Arg::allow_negative_numbers].See also [
trailing_var_arg][Arg::trailing_var_arg].NOTE: Setting this requires [taking values][Arg::num_args]
WARNING: Prior arguments with
allow_hyphen_values(true)get precedence over known flags but known flags get precedence over the next possible positional argument withallow_hyphen_values(true). When combined with [Arg::num_args(..)],Arg::value_terminatoris one way to ensure processing stops.WARNING: Take caution when using this setting combined with another argument using
Arg::num_args, as this becomes ambiguous$ prog --arg -- -- val. All three--, --, valwill be values when the user may have thought the second--would constitute the normal, "Only positional args follow" idiom.Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!;Not setting
Arg::allow_hyphen_values(true)and supplying a value which starts with a hyphen is an error.# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!; assert_eq!;fn allow_negative_numbers(self: Self, yes: bool) -> SelfAllows negative numbers to pass as values.
This is similar to
Arg::allow_hyphen_valuesexcept that it only allows numbers, all other undefined leading hyphens will fail to parse.NOTE: Setting this requires [taking values][Arg::num_args]
Examples
# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!; let m = res.unwrap; assert_eq!;fn require_equals(self: Self, yes: bool) -> SelfRequires that options use the
--option=valsyntaxi.e. an equals between the option and associated value.
NOTE: Setting this requires [taking values][Arg::num_args]
Examples
Setting
require_equalsrequires that the option have an equals sign between it and the associated value.# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!;Setting
require_equalsand not supplying the equals will cause an error.# use clap_builder as clap; # use ; let res = new .arg .try_get_matches_from; assert!; assert_eq!;fn value_delimiter<impl IntoResettable<char>: IntoResettable<char>>(self: Self, d: impl IntoResettable<char>) -> SelfAllow grouping of multiple values via a delimiter.
i.e. allow values (
val1,val2,val3) to be parsed as three values (val1,val2, andval3) instead of one value (val1,val2,val3).Examples
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!fn value_terminator<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, term: impl IntoResettable<Str>) -> SelfSentinel to stop parsing multiple values of a given argument.
By default when one sets
num_args(1..)on an argument, clap will continue parsing values for that argument until it reaches another valid argument, or one of the other more specific settings for multiple values is used (such asnum_args).NOTE: This setting only applies to options and positional arguments
NOTE: When the terminator is passed in on the command line, it is not stored as one of the values
Examples
# use clap_builder as clap; # use ; new .action .num_args .value_terminator # ;The following example uses two arguments, a sequence of commands, and the location in which to perform them
# use clap_builder as clap; # use ; let m = new .arg .arg .get_matches_from; let cmds: = m..unwrap.collect; assert_eq!; assert_eq!;fn raw(self: Self, yes: bool) -> SelfConsume all following arguments.
Do not parse them individually, but rather pass them in entirety.
It is worth noting that setting this requires all values to come after a
--to indicate they should all be captured. For example:--foo something -- -v -v -v -b -b -b --baz -q -u -xWill result in everything after
--to be considered one raw argument. This behavior may not be exactly what you are expecting and usingArg::trailing_var_argmay be more appropriate.NOTE: Implicitly sets
Arg::action(ArgAction::Set)Arg::num_args(1..),Arg::allow_hyphen_values(true), andArg::last(true)when set totrue.fn default_value<impl IntoResettable<OsStr>: IntoResettable<OsStr>>(self: Self, val: impl IntoResettable<OsStr>) -> SelfValue for the argument when not present.
Like with command-line values, this will be split by
Arg::value_delimiter.NOTE: If the user does not use this argument at runtime
ArgMatches::contains_idwill still returntrue. If you wish to determine whether the argument was used at runtime or not, consider [ArgMatches::value_source][crate::ArgMatches::value_source].NOTE: This setting is perfectly compatible with
Arg::default_value_ifbut slightly different.Arg::default_valueonly takes effect when the user has not provided this arg at runtime.Arg::default_value_ifhowever only takes effect when the user has not provided a value at runtime and these other conditions are met as well. If you have setArg::default_valueandArg::default_value_if, and the user did not provide this arg at runtime, nor were the conditions met forArg::default_value_if, theArg::default_valuewill be applied.Examples
First we use the default value without providing any value at runtime.
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!; assert!; assert_eq!;Next we provide a value at runtime to override the default.
# use clap_builder as clap; # use ; let m = new .arg .get_matches_from; assert_eq!; assert!; assert_eq!;fn default_values<impl Into<OsStr>: Into<OsStr>, impl IntoIterator<Item = impl Into<OsStr>>: IntoIterator<Item = impl Into<OsStr>>>(self: Self, vals: impl IntoIterator<Item = impl Into<OsStr>>) -> SelfValue for the argument when not present.
See
Arg::default_value.fn default_missing_value<impl IntoResettable<OsStr>: IntoResettable<OsStr>>(self: Self, val: impl IntoResettable<OsStr>) -> SelfValue for the argument when the flag is present but no value is specified.
This configuration option is often used to give the user a shortcut and allow them to efficiently specify an option argument without requiring an explicitly value. The
--colorargument is a common example. By supplying a default, such asdefault_missing_value("always"), the user can quickly just add--colorto the command line to produce the desired color output.Like with command-line values, this will be split by
Arg::value_delimiter.NOTE: using this configuration option requires the use of the [
.num_args(0..N)][Arg::num_args] and the [.require_equals(true)][Arg::require_equals] configuration option. These are required in order to unambiguously determine what, if any, value was supplied for the argument.Examples
For POSIX style
--color:# use clap_builder as clap; # use ; // first, we'll provide no arguments let m = cli.get_matches_from; assert_eq!; assert_eq!; // next, we'll provide a runtime value to override the default (as usually done). let m = cli.get_matches_from; assert_eq!; assert_eq!; // finally, we will use the shortcut and only provide the argument without a value. let m = cli.get_matches_from; assert_eq!; assert_eq!;For bool literals:
# use clap_builder as clap; # use ; // first, we'll provide no arguments let m = cli.get_matches_from; assert_eq!; // next, we'll provide a runtime value to override the default (as usually done). let m = cli.get_matches_from; assert_eq!; assert_eq!; // finally, we will use the shortcut and only provide the argument without a value. let m = cli.get_matches_from; assert_eq!; assert_eq!;fn default_missing_value_os<impl Into<OsStr>: Into<OsStr>>(self: Self, val: impl Into<OsStr>) -> SelfValue for the argument when the flag is present but no value is specified.
fn default_missing_values<impl Into<OsStr>: Into<OsStr>, impl IntoIterator<Item = impl Into<OsStr>>: IntoIterator<Item = impl Into<OsStr>>>(self: Self, vals: impl IntoIterator<Item = impl Into<OsStr>>) -> SelfValue for the argument when the flag is present but no value is specified.
fn default_missing_values_os<impl Into<OsStr>: Into<OsStr>, impl IntoIterator<Item = impl Into<OsStr>>: IntoIterator<Item = impl Into<OsStr>>>(self: Self, vals: impl IntoIterator<Item = impl Into<OsStr>>) -> SelfValue for the argument when the flag is present but no value is specified.
impl Arg
fn get_id(self: &Self) -> &IdGet the name of the argument
fn get_help(self: &Self) -> Option<&StyledStr>Get the help specified for this argument, if any
fn get_long_help(self: &Self) -> Option<&StyledStr>Get the long help specified for this argument, if any
Examples
# use clap_builder as clap; # use Arg; let arg = new.long_help; assert_eq!;fn get_display_order(self: &Self) -> usizeGet the placement within help
fn get_help_heading(self: &Self) -> Option<&str>Get the help heading specified for this argument, if any
fn get_short(self: &Self) -> Option<char>Get the short option name for this argument, if any
fn get_visible_short_aliases(self: &Self) -> Option<Vec<char>>Get visible short aliases for this argument, if any
fn get_all_short_aliases(self: &Self) -> Option<Vec<char>>Get all short aliases for this argument, if any, both visible and hidden.
fn get_short_and_visible_aliases(self: &Self) -> Option<Vec<char>>Get the short option name and its visible aliases, if any
fn get_long(self: &Self) -> Option<&str>Get the long option name for this argument, if any
fn get_visible_aliases(self: &Self) -> Option<Vec<&str>>Get visible aliases for this argument, if any
fn get_all_aliases(self: &Self) -> Option<Vec<&str>>Get all aliases for this argument, if any, both visible and hidden.
fn get_long_and_visible_aliases(self: &Self) -> Option<Vec<&str>>Get the long option name and its visible aliases, if any
fn get_aliases(self: &Self) -> Option<Vec<&str>>Get hidden aliases for this argument, if any
fn get_possible_values(self: &Self) -> Vec<PossibleValue>Get the names of possible values for this argument. Only useful for user facing applications, such as building help messages or man files
fn get_value_names(self: &Self) -> Option<&[Str]>Get the names of values for this argument.
fn get_num_args(self: &Self) -> Option<ValueRange>Get the number of values for this argument.
fn get_value_delimiter(self: &Self) -> Option<char>Get the delimiter between multiple values
fn get_value_terminator(self: &Self) -> Option<&Str>Get the value terminator for this argument. The
value_terminatoris a value that terminates parsing of multi-valued arguments.fn get_index(self: &Self) -> Option<usize>Get the index of this argument, if any
fn get_value_hint(self: &Self) -> ValueHintGet the value hint of this argument
fn get_default_values(self: &Self) -> &[OsStr]Get the default values specified for this argument, if any
Examples
# use clap_builder as clap; # use Arg; let arg = new.default_value; assert_eq!;fn is_positional(self: &Self) -> boolChecks whether this argument is a positional or not.
Examples
# use clap_builder as clap; # use Arg; let arg = new; assert_eq!; let arg = new.long; assert_eq!;fn is_required_set(self: &Self) -> boolReports whether
Arg::requiredis setfn is_allow_hyphen_values_set(self: &Self) -> boolReport whether
Arg::allow_hyphen_valuesis setfn is_allow_negative_numbers_set(self: &Self) -> boolReport whether
Arg::allow_negative_numbersis setfn get_action(self: &Self) -> &ArgActionBehavior when parsing the argument
fn get_value_parser(self: &Self) -> &super::ValueParserConfigured parser for argument values
Example
# use clap_builder as clap; let cmd = new .arg; let value_parser = cmd.get_arguments .find.unwrap .get_value_parser; println!;fn is_global_set(self: &Self) -> boolReport whether
Arg::globalis setfn is_next_line_help_set(self: &Self) -> boolReport whether
Arg::next_line_helpis setfn is_hide_set(self: &Self) -> boolReport whether
Arg::hideis setfn is_hide_default_value_set(self: &Self) -> boolReport whether
Arg::hide_default_valueis setfn is_hide_possible_values_set(self: &Self) -> boolReport whether
Arg::hide_possible_valuesis setfn is_hide_short_help_set(self: &Self) -> boolReport whether
Arg::hide_short_helpis setfn is_hide_long_help_set(self: &Self) -> boolReport whether
Arg::hide_long_helpis setfn is_require_equals_set(self: &Self) -> boolReport whether
Arg::require_equalsis setfn is_exclusive_set(self: &Self) -> boolReports whether
Arg::exclusiveis setfn is_trailing_var_arg_set(self: &Self) -> boolReport whether
Arg::trailing_var_argis setfn is_last_set(self: &Self) -> boolReports whether
Arg::lastis setfn is_ignore_case_set(self: &Self) -> boolReports whether
Arg::ignore_caseis set
impl Clone for Arg
fn clone(self: &Self) -> Arg
impl Debug for Arg
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result<(), fmt::Error>
impl Default for Arg
fn default() -> Arg
impl Display for Arg
fn fmt(self: &Self, f: &mut Formatter<'_>) -> fmt::Result
impl Eq for Arg
impl Freeze for Arg
impl From for Arg
fn from(a: &Arg) -> Self
impl Ord for Arg
fn cmp(self: &Self, other: &Arg) -> Ordering
impl PartialEq for Arg
fn eq(self: &Self, other: &Arg) -> bool
impl PartialOrd for Arg
fn partial_cmp(self: &Self, other: &Self) -> Option<Ordering>
impl RefUnwindSafe for Arg
impl Send for Arg
impl Sync for Arg
impl Unpin for Arg
impl UnwindSafe for Arg
impl<T> Any for Arg
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Arg
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Arg
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Arg
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Arg
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Arg
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Arg
fn to_string(self: &Self) -> String
impl<T, U> Into for Arg
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Arg
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Arg
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>