Struct PossibleValuesParser

struct PossibleValuesParser(_)

Verify the value is from an enumerated set of [PossibleValue][crate::builder::PossibleValue].

See also:

Example

Usage:

# use clap_builder as clap;
let mut cmd = clap::Command::new("raw")
    .arg(
        clap::Arg::new("color")
            .value_parser(clap::builder::PossibleValuesParser::new(["always", "auto", "never"]))
            .required(true)
    );

let m = cmd.try_get_matches_from_mut(["cmd", "always"]).unwrap();
let port: &String = m.get_one("color")
    .expect("required");
assert_eq!(port, "always");

Semantics:

# use clap_builder as clap;
# use std::ffi::OsStr;
# use clap::builder::TypedValueParser;
# let cmd = clap::Command::new("test");
# let arg = None;
let value_parser = clap::builder::PossibleValuesParser::new(["always", "auto", "never"]);
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("random")).is_err());
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("")).is_err());
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("always")).unwrap(), "always");
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("auto")).unwrap(), "auto");
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("never")).unwrap(), "never");

Implementations

impl PossibleValuesParser

fn new<impl Into<PossibleValuesParser>: Into<PossibleValuesParser>>(values: impl Into<PossibleValuesParser>) -> Self

Verify the value is from an enumerated set of [PossibleValue][crate::builder::PossibleValue].

impl Clone for PossibleValuesParser

fn clone(self: &Self) -> PossibleValuesParser

impl Debug for PossibleValuesParser

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

impl Freeze for PossibleValuesParser

impl RefUnwindSafe for PossibleValuesParser

impl Send for PossibleValuesParser

impl Sync for PossibleValuesParser

impl TypedValueParser for PossibleValuesParser

fn parse_ref(self: &Self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<<Self as >::Value, Error>
fn parse(self: &Self, cmd: &Command, arg: Option<&Arg>, value: OsString) -> Result<String, Error>
fn possible_values(self: &Self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>

impl Unpin for PossibleValuesParser

impl UnsafeUnpin for PossibleValuesParser

impl UnwindSafe for PossibleValuesParser

impl<I> IntoResettable for PossibleValuesParser

fn into_resettable(self: Self) -> Resettable<ValueParser>

impl<I, T> From for PossibleValuesParser

fn from(values: I) -> Self

impl<T> Any for PossibleValuesParser

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for PossibleValuesParser

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

impl<T> BorrowMut for PossibleValuesParser

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

impl<T> CloneToUninit for PossibleValuesParser

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

impl<T> From for PossibleValuesParser

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for PossibleValuesParser

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

impl<T, U> Into for PossibleValuesParser

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 PossibleValuesParser

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

impl<T, U> TryInto for PossibleValuesParser

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