Skip to main content

Shell

Struct Shell 

Source
pub struct Shell { /* private fields */ }
Expand description

A virtual Bash environment.

Create one with Shell::new for defaults or Shell::builder for full control. The filesystem persists across exec calls; shell state (variables, functions, cwd) is isolated per call.

Implementations§

Source§

impl Shell

Source

pub fn new() -> Self

Create an instance with default settings and an empty in-memory filesystem.

Source

pub fn builder() -> Builder

Start building a configured instance.

Source

pub fn exec(&mut self, command: &str) -> Result<ExecResult, Error>

Execute a bash command string.

Shell state (variables, functions, working directory) is isolated per call - each invocation starts fresh. The filesystem is shared and persists across calls.

§Errors

Returns Error::Parse for syntax errors, Error::LimitExceeded if an execution limit is hit. Note that a non-zero exit code is not an error - it’s reported in ExecResult::exit_code.

Source

pub fn exec_with( &mut self, command: &str, options: ExecOptions<'_>, ) -> Result<ExecResult, Error>

Execute with custom options (stdin, env overrides, cwd override).

Source

pub fn register_command(&mut self, name: impl Into<String>, func: CommandFn)

Register a custom command after construction.

Source

pub fn exec_with_timeout( &mut self, command: &str, timeout: Duration, ) -> Result<ExecResult, Error>

Execute a command with a timeout. Spawns a timer thread that cancels execution after the given duration.

Source

pub fn fs(&self) -> &dyn VirtualFs

Direct access to the virtual filesystem.

Source

pub fn read_file(&self, path: &str) -> Result<String, Error>

Read a file as a UTF-8 string.

Source

pub fn write_file(&self, path: &str, content: &str) -> Result<(), Error>

Write a UTF-8 string to a file (creates parent directories).

Source

pub fn cwd(&self) -> &str

Current working directory.

Source

pub fn env(&self) -> &HashMap<String, String>

Current default environment variables.

Trait Implementations§

Source§

impl Debug for Shell

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Shell

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Shell

§

impl !RefUnwindSafe for Shell

§

impl !Send for Shell

§

impl !Sync for Shell

§

impl Unpin for Shell

§

impl UnsafeUnpin for Shell

§

impl !UnwindSafe for Shell

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> Same for T

Source§

type Output = T

Should always be Self
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.