Struct clap_builder::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§
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<Self::Value, Error>
fn parse_ref( &self, cmd: &Command, arg: Option<&Arg>, value: &OsStr ) -> Result<Self::Value, Error>
Parse the argument value Read more
source§fn parse_ref_(
&self,
cmd: &Command,
arg: Option<&Arg>,
_value: &OsStr,
source: ValueSource
) -> Result<Self::Value, Error>
fn parse_ref_( &self, cmd: &Command, arg: Option<&Arg>, _value: &OsStr, source: ValueSource ) -> Result<Self::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<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