pub struct BuiltinContext<'a> {
pub args: &'a [String],
pub env: &'a HashMap<String, String>,
pub variables: &'a mut HashMap<String, String>,
pub cwd: &'a mut PathBuf,
pub fs: Arc<dyn FileSystem>,
pub stdin: Option<&'a str>,
}Expand description
Execution context for builtin commands.
Provides access to the shell execution environment including arguments, variables, filesystem, and pipeline input.
§Example
use bashkit::{Builtin, BuiltinContext, ExecResult, async_trait};
struct Echo;
#[async_trait]
impl Builtin for Echo {
async fn execute(&self, ctx: BuiltinContext<'_>) -> bashkit::Result<ExecResult> {
// Access command arguments
let output = ctx.args.join(" ");
// Access environment variables
let _home = ctx.env.get("HOME");
// Access pipeline input
if let Some(stdin) = ctx.stdin {
return Ok(ExecResult::ok(stdin.to_string()));
}
Ok(ExecResult::ok(format!("{}\n", output)))
}
}Fields§
§args: &'a [String]Command arguments (not including the command name).
For mycommand arg1 arg2, this contains ["arg1", "arg2"].
env: &'a HashMap<String, String>Environment variables.
Read-only access to variables set via BashBuilder::env
or the export builtin.
variables: &'a mut HashMap<String, String>Shell variables (mutable).
Allows builtins to set or modify shell variables.
cwd: &'a mut PathBufCurrent working directory (mutable).
Used by cd and path resolution.
fs: Arc<dyn FileSystem>Virtual filesystem.
Provides async file operations (read, write, mkdir, etc.).
stdin: Option<&'a str>Standard input from pipeline.
Contains output from the previous command in a pipeline.
For echo hello | mycommand, stdin will be Some("hello\n").
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> !RefUnwindSafe for Context<'a>
impl<'a> Send for Context<'a>
impl<'a> Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> !UnwindSafe for Context<'a>
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