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
impl Shell
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an instance with default settings and an empty in-memory filesystem.
Sourcepub fn exec(&mut self, command: &str) -> Result<ExecResult, Error>
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.
Sourcepub fn exec_with(
&mut self,
command: &str,
options: ExecOptions<'_>,
) -> Result<ExecResult, Error>
pub fn exec_with( &mut self, command: &str, options: ExecOptions<'_>, ) -> Result<ExecResult, Error>
Execute with custom options (stdin, env overrides, cwd override).
Sourcepub fn register_command(&mut self, name: impl Into<String>, func: CommandFn)
pub fn register_command(&mut self, name: impl Into<String>, func: CommandFn)
Register a custom command after construction.
Sourcepub fn exec_with_timeout(
&mut self,
command: &str,
timeout: Duration,
) -> Result<ExecResult, Error>
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.