Skip to main content

BuiltinContext

Struct BuiltinContext 

Source
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 PathBuf

Current 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.