use crate::filesystem::Filesystem;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Output {
pub stdout: String,
pub stderr: String,
pub code: i32,
}
impl Output {
pub fn ok(stdout: impl Into<String>) -> Self {
Self { stdout: stdout.into(), stderr: String::new(), code: 0 }
}
pub fn err(stderr: impl Into<String>, code: i32) -> Self {
Self { stdout: String::new(), stderr: stderr.into(), code: if code == 0 { 1 } else { code } }
}
}
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
pub trait BashHost {
fn fs(&self) -> &dyn Filesystem;
async fn run_builtin(&mut self, cmd: &str, args: &[String], stdin: &str) -> Output {
crate::bashlite::builtins::dispatch(self.fs(), cmd, args, stdin).await
}
}