1use anyhow::{Result, anyhow};
2
3use mvm_core::build_env::ShellEnvironment;
4
5use crate::{shell, ui};
6
7pub struct RuntimeBuildEnv;
12
13impl ShellEnvironment for RuntimeBuildEnv {
14 fn shell_exec(&self, script: &str) -> Result<()> {
15 let out = shell::run_in_vm(script)?;
16 if out.status.success() {
17 Ok(())
18 } else {
19 Err(anyhow!(
20 "Command failed (exit {}): {}",
21 out.status.code().unwrap_or(-1),
22 String::from_utf8_lossy(&out.stderr).trim()
23 ))
24 }
25 }
26
27 fn shell_exec_stdout(&self, script: &str) -> Result<String> {
28 let out = shell::run_in_vm(script)?;
29 if !out.status.success() {
30 return Err(anyhow!(
31 "Command failed (exit {}): {}",
32 out.status.code().unwrap_or(-1),
33 String::from_utf8_lossy(&out.stderr).trim()
34 ));
35 }
36 Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())
37 }
38
39 fn shell_exec_visible(&self, script: &str) -> Result<()> {
40 shell::run_in_vm_visible(script)
41 }
42
43 fn log_info(&self, msg: &str) {
44 ui::info(msg);
45 }
46
47 fn log_success(&self, msg: &str) {
48 ui::success(msg);
49 }
50
51 fn log_warn(&self, msg: &str) {
52 ui::warn(msg);
53 }
54}