Struct UnknownArgumentValueParser

pub struct UnknownArgumentValueParser { /* private fields */ }

When encountered, report [ErrorKind::UnknownArgument][crate::error::ErrorKind::UnknownArgument]

Useful to help users migrate, either from old versions or similar tools.

Examples

# use clap_builder as clap;
# use clap::Command;
# use clap::Arg;
let cmd = Command::new("mycmd")
    .args([
        Arg::new("current-dir")
            .short('C'),
        Arg::new("current-dir-unknown")
            .long("cwd")
            .aliases(["current-dir", "directory", "working-directory", "root"])
            .value_parser(clap::builder::UnknownArgumentValueParser::suggest_arg("-C"))
            .hide(true),
    ]);

// Use a supported version of the argument
let matches = cmd.clone().try_get_matches_from(["mycmd", "-C", ".."]).unwrap();
assert!(matches.contains_id("current-dir"));
assert_eq!(
    matches.get_many::<String>("current-dir").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>(),
    vec![".."]
);

// Use one of the invalid versions
let err = cmd.try_get_matches_from(["mycmd", "--cwd", ".."]).unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);

Implementations

impl UnknownArgumentValueParser

fn suggest_arg(arg: impl Into<Str>) -> Self

Suggest an alternative argument

fn suggest(text: impl Into<StyledStr>) -> Self

Provide a general suggestion

fn and_suggest(self, text: impl Into<StyledStr>) -> Self

Extend the suggestions

Trait Implementations

impl Clone for UnknownArgumentValueParser

fn clone(&self) -> UnknownArgumentValueParser

impl Debug for UnknownArgumentValueParser

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

impl TypedValueParser for UnknownArgumentValueParser

type Value = String;
fn parse_ref(&self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<Self::Value, Error>
fn parse_ref_(&self, cmd: &Command, arg: Option<&Arg>, _value: &OsStr, source: ValueSource) -> Result<Self::Value, Error>

Auto Trait Implementations

impl Freeze for UnknownArgumentValueParser

impl RefUnwindSafe for UnknownArgumentValueParser

impl Send for UnknownArgumentValueParser

impl Sync for UnknownArgumentValueParser

impl Unpin for UnknownArgumentValueParser

impl UnsafeUnpin for UnknownArgumentValueParser

impl UnwindSafe for UnknownArgumentValueParser

Blanket Implementations

impl<I> IntoResettable<ValueParser> for UnknownArgumentValueParser where I: Into<ValueParser>,

fn into_resettable(self) -> Resettable<ValueParser>

impl<T> Any for UnknownArgumentValueParser where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for UnknownArgumentValueParser where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for UnknownArgumentValueParser where T: ?Sized,

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

impl<T> CloneToUninit for UnknownArgumentValueParser where T: Clone,

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

impl<T> From<T> for UnknownArgumentValueParser

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for UnknownArgumentValueParser where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for UnknownArgumentValueParser where U: From<T>,

fn into(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<U> for UnknownArgumentValueParser where U: Into<T>,

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

impl<T, U> TryInto<U> for UnknownArgumentValueParser where U: TryFrom<T>,

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