Struct PossibleValue

struct PossibleValue { ... }

A possible value of an argument.

This is used for specifying possible values of Args.

See also [PossibleValuesParser][crate::builder::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

# use clap_builder as clap;
# use clap::{Arg, builder::PossibleValue, ArgAction};
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

impl PossibleValue

fn new<impl Into<Str>: Into<Str>>(name: impl Into<Str>) -> Self

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

# use clap_builder as clap;
# use clap::builder::PossibleValue;
PossibleValue::new("fast")
# ;
fn help<impl IntoResettable<StyledStr>: IntoResettable<StyledStr>>(self: Self, help: impl IntoResettable<StyledStr>) -> Self

Sets the help description of the value.

This is typically displayed in completions (where supported) and should be a short, one-line description.

Examples

# use clap_builder as clap;
# use clap::builder::PossibleValue;
PossibleValue::new("slow")
    .help("not fast")
# ;
fn hide(self: Self, yes: bool) -> Self

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

# use clap_builder as clap;
# use clap::builder::PossibleValue;
PossibleValue::new("secret")
    .hide(true)
# ;
fn alias<impl IntoResettable<Str>: IntoResettable<Str>>(self: Self, name: impl IntoResettable<Str>) -> Self

Sets a hidden alias for this argument value.

Examples

# use clap_builder as clap;
# use clap::builder::PossibleValue;
PossibleValue::new("slow")
    .alias("not-fast")
# ;
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>>) -> Self

Sets multiple hidden aliases for this argument value.

Examples

# use clap_builder as clap;
# use clap::builder::PossibleValue;
PossibleValue::new("slow")
    .aliases(["not-fast", "snake-like"])
# ;

impl PossibleValue

fn get_name(self: &Self) -> &str

Get the name of the argument value

fn get_help(self: &Self) -> Option<&StyledStr>

Get the help specified for this argument, if any

fn is_hide_set(self: &Self) -> bool

Report if PossibleValue::hide is set

fn get_name_and_aliases(self: &Self) -> impl Iterator<Item = &str> + '_

Returns all valid values of the argument value.

Namely the name and all aliases.

fn matches(self: &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

# use clap_builder as clap;
# use clap::builder::PossibleValue;
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));

impl Clone for PossibleValue

fn clone(self: &Self) -> PossibleValue

impl Debug for PossibleValue

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Default for PossibleValue

fn default() -> PossibleValue

impl Eq for PossibleValue

impl Freeze for PossibleValue

impl PartialEq for PossibleValue

fn eq(self: &Self, other: &PossibleValue) -> bool

impl RefUnwindSafe for PossibleValue

impl Send for PossibleValue

impl StructuralPartialEq for PossibleValue

impl Sync for PossibleValue

impl Unpin for PossibleValue

impl UnsafeUnpin for PossibleValue

impl UnwindSafe for PossibleValue

impl<S: Into<crate::builder::Str>> From for PossibleValue

fn from(s: S) -> Self

impl<T> Any for PossibleValue

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for PossibleValue

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for PossibleValue

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for PossibleValue

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for PossibleValue

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for PossibleValue

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for PossibleValue

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for PossibleValue

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for PossibleValue

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>