Struct clap::builder::PossibleValue
source · pub struct PossibleValue { /* private fields */ }
Expand description
A possible value of an argument.
This is used for specifying possible values of Args.
See also PossibleValuesParser
NOTE: Most likely you can use strings, rather than PossibleValue
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")
.action(ArgAction::Set)
.value_name("FILE")
.value_parser([
PossibleValue::new("fast"),
PossibleValue::new("slow").help("slower than fast"),
PossibleValue::new("secret speed").hide(true)
]);
Implementations§
source§impl PossibleValue
impl PossibleValue
sourcepub fn new(name: impl Into<Str>) -> PossibleValue
pub fn new(name: impl Into<Str>) -> PossibleValue
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")
sourcepub fn help(self, help: impl IntoResettable<StyledStr>) -> PossibleValue
pub fn help(self, help: impl IntoResettable<StyledStr>) -> PossibleValue
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")
sourcepub fn hide(self, yes: bool) -> PossibleValue
pub fn hide(self, yes: bool) -> PossibleValue
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)
sourcepub fn alias(self, name: impl IntoResettable<Str>) -> PossibleValue
pub fn alias(self, name: impl IntoResettable<Str>) -> PossibleValue
Sets a hidden alias for this argument value.
§Examples
PossibleValue::new("slow")
.alias("not-fast")
sourcepub fn aliases(
self,
names: impl IntoIterator<Item = impl Into<Str>>,
) -> PossibleValue
pub fn aliases( self, names: impl IntoIterator<Item = impl Into<Str>>, ) -> PossibleValue
Sets multiple hidden aliases for this argument value.
§Examples
PossibleValue::new("slow")
.aliases(["not-fast", "snake-like"])
source§impl PossibleValue
impl PossibleValue
Reflection
sourcepub fn is_hide_set(&self) -> bool
pub fn is_hide_set(&self) -> bool
Report if PossibleValue::hide
is set
sourcepub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str>
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str>
Returns all valid values of the argument value.
Namely the name and all aliases.
sourcepub fn matches(&self, value: &str, ignore_case: bool) -> bool
pub fn matches(&self, value: &str, ignore_case: bool) -> bool
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§
source§impl Clone for PossibleValue
impl Clone for PossibleValue
source§fn clone(&self) -> PossibleValue
fn clone(&self) -> PossibleValue
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PossibleValue
impl Debug for PossibleValue
source§impl Default for PossibleValue
impl Default for PossibleValue
source§fn default() -> PossibleValue
fn default() -> PossibleValue
source§impl<S> From<S> for PossibleValue
impl<S> From<S> for PossibleValue
source§fn from(s: S) -> PossibleValue
fn from(s: S) -> PossibleValue
source§impl PartialEq for PossibleValue
impl PartialEq for PossibleValue
source§fn eq(&self, other: &PossibleValue) -> bool
fn eq(&self, other: &PossibleValue) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for PossibleValue
impl StructuralPartialEq for PossibleValue
Auto Trait Implementations§
impl Freeze for PossibleValue
impl RefUnwindSafe for PossibleValue
impl Send for PossibleValue
impl Sync for PossibleValue
impl Unpin for PossibleValue
impl UnwindSafe for PossibleValue
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)