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