#[non_exhaustive]pub struct CommandContext {
pub credential: CredentialResolver,
pub args: ValueMap,
pub user_args: ValueMap,
pub command_path: String,
pub middleware: Middleware,
pub raw_matches: Arc<ArgMatches>,
}Expand description
Runtime context passed to advanced command handlers.
Most commands can use RuntimeCommandSpec::new and receive just the
credential and effective args. Use this context when a command needs the
colon path, user-supplied args, or a snapshot of middleware state.
This struct is constructed by the framework during command dispatch. Consumer code receives it in handler closures and should not construct it directly.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.credential: CredentialResolverLazy credential resolver.
args: ValueMapEffective arguments, including defaults and framework-injected values.
user_args: ValueMapArguments explicitly supplied by the user.
command_path: StringColon-separated command path such as project:list.
middleware: MiddlewareMiddleware snapshot for this invocation.
raw_matches: Arc<ArgMatches>Raw clap matches for typed argument deserialization via derive.
Implementations§
Source§impl CommandContext
impl CommandContext
Sourcepub fn typed_args<T: FromArgMatches>(&self) -> Result<T>
pub fn typed_args<T: FromArgMatches>(&self) -> Result<T>
Deserializes the raw argument matches into a typed args struct.
Use this with #[derive(clap::Args)] structs to get type-safe access
to command arguments instead of working with the ValueMap directly.
§Errors
Returns an error if the matches cannot be deserialized into T.
Sourcepub async fn credential(&self) -> Result<Credential>
pub async fn credential(&self) -> Result<Credential>
Resolves the credential for this command, triggering the auth flow on first use and memoizing the result.
Convenience wrapper over self.credential.resolve().
§Errors
Returns an error when the command is marked no_auth, or when the auth
provider fails to produce a credential.
Sourcepub async fn try_credential(&self) -> Result<Option<Credential>>
pub async fn try_credential(&self) -> Result<Option<Credential>>
Resolves the credential when one is available, returning Ok(None) for
no-auth commands.
Convenience wrapper over self.credential.try_resolve().
§Errors
Propagates the auth provider error when resolution is attempted and fails.
Trait Implementations§
Source§impl Clone for CommandContext
impl Clone for CommandContext
Source§fn clone(&self) -> CommandContext
fn clone(&self) -> CommandContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more