syncable_cli/common/
command_utils.rs1use crate::error::Result;
2use std::process::{Command, Output};
3
4pub fn execute_command(cmd: &str, args: &[&str]) -> Result<Output> {
6 let output = Command::new(cmd)
7 .args(args)
8 .output()?;
9
10 Ok(output)
11}
12
13pub fn is_command_available(cmd: &str) -> bool {
15 if Command::new(cmd)
17 .arg("--version")
18 .output()
19 .map(|o| o.status.success())
20 .unwrap_or(false) {
21 return true;
22 }
23
24 if cfg!(windows) && !cmd.ends_with(".exe") {
26 let cmd_with_exe = format!("{}.exe", cmd);
27 return Command::new(&cmd_with_exe)
28 .arg("--version")
29 .output()
30 .map(|o| o.status.success())
31 .unwrap_or(false);
32 }
33
34 false
35}