2025-06-10 03:11:55 +02:00

35 lines
693 B
Rust

use std::{collections::HashMap, process::Command};
#[cfg(not(unix))]
use tracing::warn;
use super::shell::Shell;
pub fn shell_command<S>(
command: &str,
interactive: bool,
envs: &HashMap<String, String, S>,
) -> Command {
let shell = Shell::from_env().unwrap_or_default();
let mut cmd = Command::new(shell.executable());
cmd.arg(match shell {
Shell::PowerShell => "-Command",
Shell::Cmd => "/C",
_ => "-c",
});
#[cfg(unix)]
if interactive {
cmd.arg("-i");
}
#[cfg(not(unix))]
if interactive {
warn!("Interactive mode is not supported on Windows.");
}
cmd.envs(envs).arg(command);
cmd
}