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).args(args).output()?;
7
8 Ok(output)
9}
10
11pub fn is_command_available(cmd: &str) -> bool {
13 if Command::new(cmd)
15 .arg("--version")
16 .output()
17 .map(|o| o.status.success())
18 .unwrap_or(false)
19 {
20 return true;
21 }
22
23 if cfg!(windows) && !cmd.ends_with(".exe") {
25 let cmd_with_exe = format!("{}.exe", cmd);
26 return Command::new(&cmd_with_exe)
27 .arg("--version")
28 .output()
29 .map(|o| o.status.success())
30 .unwrap_or(false);
31 }
32
33 false
34}