pub struct UnknownArgumentValueParser { /* private fields */ }
Expand description
When encountered, report ErrorKind::UnknownArgument
Useful to help users migrate, either from old versions or similar tools.
§Examples
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§
Source§impl UnknownArgumentValueParser
impl UnknownArgumentValueParser
Sourcepub fn suggest_arg(arg: impl Into<Str>) -> UnknownArgumentValueParser
pub fn suggest_arg(arg: impl Into<Str>) -> UnknownArgumentValueParser
Suggest an alternative argument
Sourcepub fn suggest(text: impl Into<StyledStr>) -> UnknownArgumentValueParser
pub fn suggest(text: impl Into<StyledStr>) -> UnknownArgumentValueParser
Provide a general suggestion
Sourcepub fn and_suggest(
self,
text: impl Into<StyledStr>,
) -> UnknownArgumentValueParser
pub fn and_suggest( self, text: impl Into<StyledStr>, ) -> UnknownArgumentValueParser
Extend the suggestions
Trait Implementations§
Source§impl Clone for UnknownArgumentValueParser
impl Clone for UnknownArgumentValueParser
Source§fn clone(&self) -> UnknownArgumentValueParser
fn clone(&self) -> UnknownArgumentValueParser
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for UnknownArgumentValueParser
impl Debug for UnknownArgumentValueParser
Source§impl TypedValueParser for UnknownArgumentValueParser
impl TypedValueParser for UnknownArgumentValueParser
Source§fn parse_ref(
&self,
cmd: &Command,
arg: Option<&Arg>,
value: &OsStr,
) -> Result<<UnknownArgumentValueParser as TypedValueParser>::Value, Error>
fn parse_ref( &self, cmd: &Command, arg: Option<&Arg>, value: &OsStr, ) -> Result<<UnknownArgumentValueParser as TypedValueParser>::Value, Error>
Parse the argument value Read more
Source§fn parse_ref_(
&self,
cmd: &Command,
arg: Option<&Arg>,
_value: &OsStr,
source: ValueSource,
) -> Result<<UnknownArgumentValueParser as TypedValueParser>::Value, Error>
fn parse_ref_( &self, cmd: &Command, arg: Option<&Arg>, _value: &OsStr, source: ValueSource, ) -> Result<<UnknownArgumentValueParser as TypedValueParser>::Value, Error>
Parse the argument value Read more
Source§fn parse(
&self,
cmd: &Command,
arg: Option<&Arg>,
value: OsString,
) -> Result<Self::Value, Error>
fn parse( &self, cmd: &Command, arg: Option<&Arg>, value: OsString, ) -> Result<Self::Value, Error>
Parse the argument value Read more
Source§fn parse_(
&self,
cmd: &Command,
arg: Option<&Arg>,
value: OsString,
_source: ValueSource,
) -> Result<Self::Value, Error>
fn parse_( &self, cmd: &Command, arg: Option<&Arg>, value: OsString, _source: ValueSource, ) -> Result<Self::Value, Error>
Parse the argument value Read more
Source§fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>
fn possible_values( &self, ) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>
Reflect on enumerated value properties Read more
Source§fn map<T, F>(self, func: F) -> MapValueParser<Self, F>
fn map<T, F>(self, func: F) -> MapValueParser<Self, F>
Adapt a
TypedValueParser
from one value to another Read moreAuto Trait Implementations§
impl Freeze for UnknownArgumentValueParser
impl RefUnwindSafe for UnknownArgumentValueParser
impl Send for UnknownArgumentValueParser
impl Sync for UnknownArgumentValueParser
impl Unpin for UnknownArgumentValueParser
impl UnwindSafe for UnknownArgumentValueParser
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I> IntoResettable<ValueParser> for Iwhere
I: Into<ValueParser>,
impl<I> IntoResettable<ValueParser> for Iwhere
I: Into<ValueParser>,
Source§fn into_resettable(self) -> Resettable<ValueParser>
fn into_resettable(self) -> Resettable<ValueParser>
Convert to the intended resettable type