pub struct Context { /* private fields */ }Expand description
Context for Clawless commands
This struct provides information about the environment that Clawless commands are executed in, access to shared resources, and configuration settings. It is passed to each command by the Clawless runtime when executing commands.
§Examples
ⓘ
#[derive(Debug, Args)]
pub struct GreetArgs {
name: String,
}
#[command]
pub async fn greet(args: GreetArgs, context: Context) -> CommandResult {
message!("Hello, {}!", args.name);
Ok(())
}Implementations§
Source§impl Context
impl Context
Sourcepub fn current_working_directory(&self) -> &CurrentWorkingDirectory
pub fn current_working_directory(&self) -> &CurrentWorkingDirectory
The working directory in which a command was called
Sourcepub fn cancellation(&self) -> &Cancellation
pub fn cancellation(&self) -> &Cancellation
The cancellation token for cooperative shutdown
Source§impl Context
impl Context
Sourcepub fn builder() -> ContextBuilder
pub fn builder() -> ContextBuilder
Creates a new Context instance
When current_working_directory is omitted, it is auto-detected from the environment.
When provided explicitly (e.g., in tests), the given value is used directly.
§Errors
Returns ContextError::CurrentWorkingDirectory if current_working_directory is not
provided and the current working directory cannot be determined from the environment.
§Examples
ⓘ
// Production: CWD auto-detected
let context = Context::builder()
.output(output)
.build()?;
// Tests: explicit CWD
let context = Context::builder()
.current_working_directory(tmp.path())
.output(output)
.build()?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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