Skip to main content

Shell

Trait Shell 

Source
pub trait Shell {
    // Required methods
    fn run_command(
        &self,
        label: &str,
        program: &str,
        args: &[&str],
        output: &mut dyn Output,
        mode: OutputMode,
    ) -> Result<CommandResult, ShellError>;
    fn shell_exec(
        &self,
        script: &str,
        output: &mut dyn Output,
        mode: OutputMode,
    ) -> Result<CommandResult, ShellError>;
    fn command_exists(&self, program: &str) -> bool;
    fn command_output(
        &self,
        program: &str,
        args: &[&str],
    ) -> Result<String, ShellError>;
    fn exec_capture(
        &self,
        cmd: &str,
        output: &mut dyn Output,
        mode: OutputMode,
    ) -> Result<CommandResult, ShellError>;
    fn exec_interactive(
        &self,
        cmd: &str,
        output: &mut dyn Output,
        mode: OutputMode,
    ) -> Result<(), ShellError>;
}
Expand description

Abstraction over shell execution, enabling unit tests to mock process spawning.

Required Methods§

Source

fn run_command( &self, label: &str, program: &str, args: &[&str], output: &mut dyn Output, mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run program with args, displaying progress under label.

Output behavior is controlled by mode:

  • quiet: output is collected silently.
  • verbose: each line is echoed with a > prefix.
  • default: an animated spinner overlay is shown.
Source

fn shell_exec( &self, script: &str, output: &mut dyn Output, mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run an arbitrary shell script string (passed to bash -c / powershell -Command).

Source

fn command_exists(&self, program: &str) -> bool

Return true when program can be found on PATH.

Source

fn command_output( &self, program: &str, args: &[&str], ) -> Result<String, ShellError>

Run program args and return its captured stdout as a trimmed String.

Source

fn exec_capture( &self, cmd: &str, output: &mut dyn Output, mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run a shell command, capturing stdout/stderr silently without display. In dry-run mode (DryRunShell), logs the command and returns success without executing.

Source

fn exec_interactive( &self, cmd: &str, output: &mut dyn Output, mode: OutputMode, ) -> Result<(), ShellError>

Run a shell command with inherited stdio (for interactive flows like aws sso login). In dry-run mode (DryRunShell), logs the command and returns success without executing.

Implementors§