zoi/project/
executor.rs

1use anyhow::{Result, anyhow};
2use colored::*;
3use std::collections::HashMap;
4use std::process::Command;
5
6pub fn run_shell_command(command_str: &str, envs: &HashMap<String, String>) -> Result<()> {
7    println!("> {}", command_str.cyan());
8    let status = if cfg!(target_os = "windows") {
9        Command::new("pwsh")
10            .arg("-Command")
11            .arg(command_str)
12            .envs(envs)
13            .status()?
14    } else {
15        Command::new("bash")
16            .arg("-c")
17            .arg(command_str)
18            .envs(envs)
19            .status()?
20    };
21
22    if !status.success() {
23        return Err(anyhow!("Command failed with exit code {status}"));
24    }
25    Ok(())
26}