cargo_lambda_interactive/
command.rs1use miette::{IntoDiagnostic, Result, WrapErr};
2use std::process::Stdio;
3use tokio::process::Command;
4
5#[cfg(target_os = "windows")]
6pub fn new_command(cmd: &str) -> Command {
7 let mut command = Command::new("cmd.exe");
8 command.arg("/c");
9 command.arg(cmd);
10 command
11}
12
13#[cfg(not(target_os = "windows"))]
14pub fn new_command(cmd: &str) -> Command {
15 Command::new(cmd)
16}
17
18pub async fn silent_command(cmd: &str, args: &[&str]) -> Result<()> {
20 let mut child = new_command(cmd)
21 .args(args)
22 .stderr(Stdio::null())
23 .stdout(Stdio::null())
24 .spawn()
25 .into_diagnostic()
26 .wrap_err_with(|| format!("Failed to run `{} {}`", cmd, args.join(" ")))?;
27
28 child
29 .wait()
30 .await
31 .into_diagnostic()
32 .wrap_err_with(|| format!("Failed to wait on {cmd} process"))
33 .map(|_| ())
34}