pub struct RustBash { /* private fields */ }Expand description
A sandboxed bash shell interpreter.
Implementations§
Source§impl RustBash
impl RustBash
Sourcepub fn exec(&mut self, input: &str) -> Result<ExecResult, RustBashError>
pub fn exec(&mut self, input: &str) -> Result<ExecResult, RustBashError>
Execute a shell command string and return the result.
Sourcepub fn last_exit_code(&self) -> i32
pub fn last_exit_code(&self) -> i32
Returns the exit code of the last executed command.
Sourcepub fn should_exit(&self) -> bool
pub fn should_exit(&self) -> bool
Returns true if the shell received an exit command.
Sourcepub fn command_names(&self) -> Vec<&str>
pub fn command_names(&self) -> Vec<&str>
Returns the names of all registered commands (builtins + custom).
Sourcepub fn command_meta(&self, name: &str) -> Option<&'static CommandMeta>
pub fn command_meta(&self, name: &str) -> Option<&'static CommandMeta>
Returns the CommandMeta for a registered command, if it provides one.
Sourcepub fn set_shell_name(&mut self, name: String)
pub fn set_shell_name(&mut self, name: String)
Sets the shell name ($0).
Sourcepub fn set_positional_params(&mut self, params: Vec<String>)
pub fn set_positional_params(&mut self, params: Vec<String>)
Sets the positional parameters ($1, $2, …).
Sourcepub fn write_file(&self, path: &str, content: &[u8]) -> Result<(), VfsError>
pub fn write_file(&self, path: &str, content: &[u8]) -> Result<(), VfsError>
Write a file to the virtual filesystem, creating parent directories.
Sourcepub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>
pub fn read_file(&self, path: &str) -> Result<Vec<u8>, VfsError>
Read a file from the virtual filesystem.
Sourcepub fn mkdir(&self, path: &str, recursive: bool) -> Result<(), VfsError>
pub fn mkdir(&self, path: &str, recursive: bool) -> Result<(), VfsError>
Create a directory in the virtual filesystem.
Sourcepub fn readdir(&self, path: &str) -> Result<Vec<DirEntry>, VfsError>
pub fn readdir(&self, path: &str) -> Result<Vec<DirEntry>, VfsError>
List entries in a directory.
Sourcepub fn remove_file(&self, path: &str) -> Result<(), VfsError>
pub fn remove_file(&self, path: &str) -> Result<(), VfsError>
Remove a file from the virtual filesystem.
Sourcepub fn remove_dir_all(&self, path: &str) -> Result<(), VfsError>
pub fn remove_dir_all(&self, path: &str) -> Result<(), VfsError>
Remove a directory (and contents if recursive) from the virtual filesystem.
Sourcepub fn register_command(&mut self, cmd: Box<dyn VirtualCommand>)
pub fn register_command(&mut self, cmd: Box<dyn VirtualCommand>)
Register a custom command.
Sourcepub fn exec_with_overrides(
&mut self,
input: &str,
env: Option<&HashMap<String, String>>,
cwd: Option<&str>,
stdin: Option<&str>,
) -> Result<ExecResult, RustBashError>
pub fn exec_with_overrides( &mut self, input: &str, env: Option<&HashMap<String, String>>, cwd: Option<&str>, stdin: Option<&str>, ) -> Result<ExecResult, RustBashError>
Execute a command with per-exec environment and cwd overrides.
Overrides are applied before execution and restored afterward.
Sourcepub fn is_input_complete(input: &str) -> bool
pub fn is_input_complete(input: &str) -> bool
Check whether input looks like a complete shell statement.
Returns true when the input can be tokenized and parsed without
hitting an “unexpected end-of-input” / unterminated-quote error.
Useful for implementing multi-line REPL input.
Note: mirrors the tokenize → parse flow from interpreter::parse().