orch/cmd_cache.rs
1use once_cell::sync::Lazy;
2use std::collections::HashMap;
3use std::sync::Mutex;
4
5static CMD_CACHE: Lazy<Mutex<HashMap<String, bool>>> = Lazy::new(|| Mutex::new(HashMap::new()));
6
7/// Check if a command exists in PATH, caching the result to avoid repeated
8/// filesystem scans (which can be expensive when called frequently).
9pub fn command_exists(cmd: &str) -> bool {
10 let mut cache = CMD_CACHE.lock().unwrap_or_else(|e| e.into_inner());
11 if let Some(v) = cache.get(cmd) {
12 return *v;
13 }
14 let ok = which::which(cmd).is_ok();
15 cache.insert(cmd.to_string(), ok);
16 ok
17}