Struct clap::PossibleValue [−][src]
pub struct PossibleValue<'help> { /* fields omitted */ }
Expand description
A possible value of an argument.
This is used for specifying possible values of Args.
NOTE: This struct is likely not needed for most usecases as it is only required to hide single values from help messages and shell completions or to attach help to possible values.
Examples
let cfg = Arg::new("config")
.takes_value(true)
.value_name("FILE")
.possible_value(PossibleValue::new("fast"))
.possible_value(PossibleValue::new("slow").help("slower than fast"))
.possible_value(PossibleValue::new("secret speed").hide(true));
Implementations
Create a PossibleValue
with its name.
The name will be used to decide whether this value was provided by the user to an argument.
NOTE: In case it is not hidden it will also be shown in help messages for arguments
that use it as a possible value and have not hidden them through Arg::hide_possible_values(true)
.
Examples
PossibleValue::new("fast")
Sets the help description of the value.
This is typically displayed in completions (where supported) and should be a short, one-line description.
Examples
PossibleValue::new("slow")
.help("not fast")
Hides this value from help and shell completions.
This is an alternative to hiding through Arg::hide_possible_values(true)
, if you only
want to hide some values.
Examples
PossibleValue::new("secret")
.hide(true)
Sets multiple hidden aliases for this argument value.
Examples
PossibleValue::new("slow")
.aliases(["not-fast", "snake-like"])
Reflection
👎 Deprecated since 3.1.0: Replaced with PossibleValue::is_hide_set
Replaced with PossibleValue::is_hide_set
Deprecated, replaced with PossibleValue::is_hide_set
Report if PossibleValue::hide
is set
👎 Deprecated since 3.1.4: Use PossibleValue::is_hide_set
and PossibleValue::get_name
Use PossibleValue::is_hide_set
and PossibleValue::get_name
Get the name if argument value is not hidden, None
otherwise
Returns all valid values of the argument value.
Namely the name and all aliases.
Tests if the value is valid for this argument value
The value is valid if it is either the name or one of the aliases.
Examples
let arg_value = PossibleValue::new("fast").alias("not-slow");
assert!(arg_value.matches("fast", false));
assert!(arg_value.matches("not-slow", false));
assert!(arg_value.matches("FAST", true));
assert!(!arg_value.matches("FAST", false));
Trait Implementations
Returns the “default value” for a type. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl<'help> RefUnwindSafe for PossibleValue<'help>
impl<'help> Send for PossibleValue<'help>
impl<'help> Sync for PossibleValue<'help>
impl<'help> Unpin for PossibleValue<'help>
impl<'help> UnwindSafe for PossibleValue<'help>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.