Struct clap::builder::UnknownArgumentValueParser
source · 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 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<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