gestura_core_tools/
shell_async.rs1use crate::error::{AppError, Result};
7use crate::shell::{CommandResult, ShellTools};
8use std::collections::HashMap;
9use std::path::PathBuf;
10
11pub async fn execute_command(command: &str, cwd: Option<&str>) -> Result<CommandResult> {
13 execute_command_with_options(command, cwd, None, Some(60)).await
14}
15
16pub async fn execute_command_with_options(
18 command: &str,
19 cwd: Option<&str>,
20 env: Option<&HashMap<String, String>>,
21 timeout_secs: Option<u64>,
22) -> Result<CommandResult> {
23 let tools = ShellTools::new();
24 let cmd = command.to_string();
25 let work_dir = cwd.map(PathBuf::from);
26 let env_map = env.cloned();
27 let timeout = timeout_secs;
28
29 tokio::task::spawn_blocking(move || {
30 tools.run_with_options(&cmd, work_dir.as_deref(), env_map.as_ref(), timeout)
31 })
32 .await
33 .map_err(|e| AppError::Io(std::io::Error::other(format!("Task join error: {}", e))))?
34}