pub struct ParseResult { /* private fields */ }Expand description
Outcome of parsing a raw argv slice against a CommandSchema.
Holds typed-but-unconverted values; callers pull values out via
ParseResult::flag, ParseResult::get, etc. Conversion happens
lazily at extraction time so a single result can be probed with
different target types during tests without repeated parsing.
Implementations§
Source§impl ParseResult
impl ParseResult
Sourcepub fn get<T: FromArg>(&self, name: &str) -> Result<Option<T>>
pub fn get<T: FromArg>(&self, name: &str) -> Result<Option<T>>
Get the last value supplied for an option, converted via FromArg.
Returns Ok(None) when the option is absent.
Looks up positional arguments as a fallback so callers don’t need two code paths for “option or argument by name”.
Sourcepub fn require<T: FromArg>(&self, name: &str) -> Result<T>
pub fn require<T: FromArg>(&self, name: &str) -> Result<T>
Like ParseResult::get but errors if the value is missing.
The error variant depends on the name shape: dash-prefixed names
(e.g. --num, -n) become MissingOption, everything else becomes
MissingArgument. That way a command that marks an option as
required via require::<T>("--num") gets a diagnostic mentioning
the option, not a positional argument.
Sourcepub fn all<T: FromArg>(&self, name: &str) -> Result<Vec<T>>
pub fn all<T: FromArg>(&self, name: &str) -> Result<Vec<T>>
Get all values supplied for a repeatable option.
Sourcepub fn subcommand(&self) -> Option<(&str, &ParseResult)>
pub fn subcommand(&self) -> Option<(&str, &ParseResult)>
Return the matched subcommand name and its parse result, if any.