Skip to main content

mvm_core/
linux_env.rs

1use anyhow::Result;
2use std::process::Output;
3
4/// Abstraction for running Linux commands.
5///
6/// On macOS: delegates to a Lima VM via `limactl shell`.
7/// On native Linux with KVM: runs bash directly on the host.
8/// In the future: could route to OrbStack, UTM, or a remote host.
9///
10/// This trait decouples the "where scripts run" question from the rest
11/// of the codebase. All VM lifecycle, build, and networking code can
12/// accept a `&dyn LinuxEnv` instead of hardcoding Lima.
13pub trait LinuxEnv: Send + Sync {
14    /// Run a bash script, capturing output.
15    fn run(&self, script: &str) -> Result<Output>;
16
17    /// Run a bash script with output visible to the user (inherited stdio).
18    fn run_visible(&self, script: &str) -> Result<()>;
19
20    /// Run a bash script and return stdout as a trimmed String.
21    fn run_stdout(&self, script: &str) -> Result<String>;
22
23    /// Run a bash script, capturing both stdout and stderr (piped, not inherited).
24    fn run_capture(&self, script: &str) -> Result<Output>;
25}