Skip to main content

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 = get_shell_command(command_str).envs(envs).status()?;
9
10    if !status.success() {
11        return Err(anyhow!("Command failed with exit code {status}"));
12    }
13    Ok(())
14}
15
16pub fn get_shell_command(command_str: &str) -> Command {
17    if cfg!(target_os = "windows") {
18        let mut cmd = Command::new("pwsh");
19        cmd.arg("-Command").arg(command_str);
20        cmd
21    } else {
22        let mut cmd = Command::new("bash");
23        cmd.arg("-c").arg(command_str);
24        cmd
25    }
26}