Expand description
The shell::Shell trait and its standard implementations.
The Shell trait and its standard implementations.
§Overview
Shell— the core trait; implement it to control how processes are spawned.ProcessShell— the production implementation; spawns real OS processes.DryRunShell— logs what would be executed and returns fake success; safe to use in dry-run workflows.MockShell— records calls and returns configurable results; intended for unit tests.ScriptedShell— drives the real spinner overlay using pre-configured output scripts; intended for overlay integration tests.
Use create to get a boxed Shell at runtime based on a dry_run
flag.
Modules§
- scripted
- Scripted shell for driving the spinner overlay in tests without spawning real OS processes.
Structs§
- Command
Result - The outcome of a completed shell command.
- DryRun
Shell - Dry-run shell: logs what would be executed and returns fake success. Probe methods (command_exists, command_output) delegate to real implementations because they are read-only and safe to call.
- Mock
Shell - Mock shell for unit tests: records calls and returns configurable results.
- Process
Shell - Production shell: delegates to the free functions in this module.
- Shell
Config - Configuration for shell execution behaviour.
Enums§
- Shell
Error - Errors that can be returned by
Shellmethods.
Traits§
- Shell
- Abstraction over shell execution, enabling unit tests to mock process spawning.
Functions§
- command_
exists - Check if a program is on PATH.
Uses
whichon unix,where.exeon windows. - command_
output - Run a command and return its stdout (trimmed).
- create
- Returns a
DryRunShellwhendry_runis true, otherwise aProcessShell. Both shells are configured withShellConfig::default(). UseProcessShellorDryRunShelldirectly if you need custom config. - run_
command - Run a shell command with mode-appropriate output:
- run_
passthrough - Run a command with stdout and stderr inherited from the parent process.
- shell_
exec - Execute a script via the system shell.
Unix:
bash -c "script", Windows:powershell -Command "script".