mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-21 10:50:07 +00:00
35 lines
693 B
Rust
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
|
|
}
|