pub struct ResolvedInvocation { /* private fields */ }Expand description
One legal invocation, projected onto the shape that matched it.
Read it through the typed accessors — text,
flag, integer, source
and their optional and repeated forms. Each one checks the read against
what the matched combination declares, and a mismatch is an
InvocationReadError: a defect in the program, reported as
cli_invocation_invalid at exit 1. There is no untyped read, so no handler
can mistake “not declared” for a legitimate false or an empty string.
Implementations§
Source§impl ResolvedInvocation
impl ResolvedInvocation
pub fn command_path(&self) -> &[String]
pub fn action_id(&self) -> &str
pub fn combination_id(&self) -> &str
pub fn output_plan(&self) -> &OutputPlan
Sourcepub fn was_explicit(
&self,
argument_id: &str,
) -> Result<bool, InvocationReadError>
pub fn was_explicit( &self, argument_id: &str, ) -> Result<bool, InvocationReadError>
Whether the caller wrote this argument, as opposed to inheriting it from the shape’s fixed value or the argument’s default.
Sourcepub fn declares(&self, argument_id: &str) -> bool
pub fn declares(&self, argument_id: &str) -> bool
Whether the matched combination declares argument_id at all.
For a handler bound to an action several combinations share, where only
some of them accept an argument: ask, then read. Reading an undeclared id
is still an InvocationReadError.
Sourcepub fn text(&self, argument_id: &str) -> Result<&str, InvocationReadError>
pub fn text(&self, argument_id: &str) -> Result<&str, InvocationReadError>
A string, enum or UUID value the combination always supplies: required, fixed, or defaulted.
Sourcepub fn optional_text(
&self,
argument_id: &str,
) -> Result<Option<&str>, InvocationReadError>
pub fn optional_text( &self, argument_id: &str, ) -> Result<Option<&str>, InvocationReadError>
A string, enum or UUID value the caller may omit.
Sourcepub fn texts(&self, argument_id: &str) -> Result<Vec<&str>, InvocationReadError>
pub fn texts(&self, argument_id: &str) -> Result<Vec<&str>, InvocationReadError>
Every value of a repeatable string, enum or UUID argument, in argv order.
Sourcepub fn flag(&self, argument_id: &str) -> Result<bool, InvocationReadError>
pub fn flag(&self, argument_id: &str) -> Result<bool, InvocationReadError>
Whether a flag was given. An absent flag the combination declares is a
legitimate false; an undeclared one is a read error, never false.
Sourcepub fn json_text(&self, argument_id: &str) -> Result<&str, InvocationReadError>
pub fn json_text(&self, argument_id: &str) -> Result<&str, InvocationReadError>
The raw source text of a json argument the combination always supplies.
Sourcepub fn optional_json_text(
&self,
argument_id: &str,
) -> Result<Option<&str>, InvocationReadError>
pub fn optional_json_text( &self, argument_id: &str, ) -> Result<Option<&str>, InvocationReadError>
The raw source text of a json argument the caller may omit.
Sourcepub fn integer<T: TryFrom<i64>>(
&self,
argument_id: &str,
) -> Result<T, InvocationReadError>
pub fn integer<T: TryFrom<i64>>( &self, argument_id: &str, ) -> Result<T, InvocationReadError>
An i64 argument converted to the integer type the handler works in.
A value that does not fit T is a read error: the registry’s
ArgSpec::range is where the bound belongs, so the caller gets a
usage error at exit 2 instead of a handler-side check.
Sourcepub fn optional_integer<T: TryFrom<i64>>(
&self,
argument_id: &str,
) -> Result<Option<T>, InvocationReadError>
pub fn optional_integer<T: TryFrom<i64>>( &self, argument_id: &str, ) -> Result<Option<T>, InvocationReadError>
An i64 argument the caller may omit, converted as integer.
Sourcepub fn integers<T: TryFrom<i64>>(
&self,
argument_id: &str,
) -> Result<Vec<T>, InvocationReadError>
pub fn integers<T: TryFrom<i64>>( &self, argument_id: &str, ) -> Result<Vec<T>, InvocationReadError>
Every value of a repeatable i64 argument, each converted as
integer.
Sourcepub fn number(&self, argument_id: &str) -> Result<f64, InvocationReadError>
pub fn number(&self, argument_id: &str) -> Result<f64, InvocationReadError>
A finite f64 argument the combination always supplies.
Sourcepub fn optional_number(
&self,
argument_id: &str,
) -> Result<Option<f64>, InvocationReadError>
pub fn optional_number( &self, argument_id: &str, ) -> Result<Option<f64>, InvocationReadError>
A finite f64 argument the caller may omit.
Sourcepub fn key_value(
&self,
argument_id: &str,
) -> Result<(&str, &str), InvocationReadError>
pub fn key_value( &self, argument_id: &str, ) -> Result<(&str, &str), InvocationReadError>
A KEY=VALUE argument the combination always supplies, split at the
first =.
Sourcepub fn optional_key_value(
&self,
argument_id: &str,
) -> Result<Option<(&str, &str)>, InvocationReadError>
pub fn optional_key_value( &self, argument_id: &str, ) -> Result<Option<(&str, &str)>, InvocationReadError>
A KEY=VALUE argument the caller may omit.
Sourcepub fn key_values(
&self,
argument_id: &str,
) -> Result<Vec<(&str, &str)>, InvocationReadError>
pub fn key_values( &self, argument_id: &str, ) -> Result<Vec<(&str, &str)>, InvocationReadError>
Every pair of a repeatable KEY=VALUE argument, in argv order.
Sourcepub fn source(
&self,
argument_id: &str,
) -> Result<&ValueSource, InvocationReadError>
pub fn source( &self, argument_id: &str, ) -> Result<&ValueSource, InvocationReadError>
Where a sourced argument’s value is, as the parser classified it.
Classification is syntax only: nothing has been read. Call
ValueSource::read or read_secret when the
value is actually needed, so a variable or file that does not exist is
a failure of the command that needed it, not of argv.
Sourcepub fn optional_source(
&self,
argument_id: &str,
) -> Result<Option<&ValueSource>, InvocationReadError>
pub fn optional_source( &self, argument_id: &str, ) -> Result<Option<&ValueSource>, InvocationReadError>
A sourced argument the caller may omit.
Sourcepub fn sources(
&self,
argument_id: &str,
) -> Result<&[ValueSource], InvocationReadError>
pub fn sources( &self, argument_id: &str, ) -> Result<&[ValueSource], InvocationReadError>
Every source of a repeatable sourced argument, in argv order.