Struct UnknownArgumentValueParser

struct UnknownArgumentValueParser { ... }

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<impl Into<Str>: Into<Str>>(arg: impl Into<Str>) -> Self

Suggest an alternative argument

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

Provide a general suggestion

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

Extend the suggestions

impl Clone for UnknownArgumentValueParser

fn clone(self: &Self) -> UnknownArgumentValueParser

impl Debug for UnknownArgumentValueParser

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

impl Freeze for UnknownArgumentValueParser

impl RefUnwindSafe for UnknownArgumentValueParser

impl Send for UnknownArgumentValueParser

impl Sync for UnknownArgumentValueParser

impl TypedValueParser for UnknownArgumentValueParser

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

impl Unpin for UnknownArgumentValueParser

impl UnsafeUnpin for UnknownArgumentValueParser

impl UnwindSafe for UnknownArgumentValueParser

impl<I> IntoResettable for UnknownArgumentValueParser

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

impl<T> Any for UnknownArgumentValueParser

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for UnknownArgumentValueParser

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

impl<T> BorrowMut for UnknownArgumentValueParser

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

impl<T> CloneToUninit for UnknownArgumentValueParser

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

impl<T> From for UnknownArgumentValueParser

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for UnknownArgumentValueParser

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

impl<T, U> Into for UnknownArgumentValueParser

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 UnknownArgumentValueParser

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

impl<T, U> TryInto for UnknownArgumentValueParser

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