pub struct CommandContext {
pub command_path: Vec<String>,
pub extensions: Extensions,
}Expand description
Context passed to command handlers.
Provides information about the execution environment plus an extensions container for injecting custom state via pre-dispatch hooks.
Note that output format is deliberately not included here - format decisions are made by the render handler, not by logic handlers.
§Extensions
Pre-dispatch hooks can inject state into extensions that handlers retrieve:
use standout_dispatch::{Hooks, HookError, CommandContext};
struct Database { /* ... */ }
let hooks = Hooks::new()
.pre_dispatch(|_matches, ctx| {
ctx.extensions.insert(Database { /* ... */ });
Ok(())
});
// In handler:
fn my_handler(matches: &clap::ArgMatches, ctx: &CommandContext) -> anyhow::Result<()> {
let db = ctx.extensions.get_required::<Database>()?;
// use db...
Ok(())
}Fields§
§command_path: Vec<String>The command path being executed (e.g., [“config”, “get”])
extensions: ExtensionsType-safe container for custom state injection.
Pre-dispatch hooks can insert values that handlers retrieve.
Trait Implementations§
Source§impl Debug for CommandContext
impl Debug for CommandContext
Source§impl Default for CommandContext
impl Default for CommandContext
Source§fn default() -> CommandContext
fn default() -> CommandContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CommandContext
impl !RefUnwindSafe for CommandContext
impl Send for CommandContext
impl Sync for CommandContext
impl Unpin for CommandContext
impl UnsafeUnpin for CommandContext
impl !UnwindSafe for CommandContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more