#[non_exhaustive]pub struct CommandContext {
pub credential: Option<Credential>,
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: Option<Credential>Credential resolved by middleware. No-auth commands receive None.
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.
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