Simple `which`-like lookup: search `$PATH` for an executable with the given name.
(binary_name: &str)
| 107 | /// Simple `which`-like lookup: search `$PATH` for an executable with |
| 108 | /// the given name. |
| 109 | fn which(binary_name: &str) -> Result<PathBuf, String> { |
| 110 | let path_var = std::env::var("PATH").map_err(|_| "PATH not set".to_string())?; |
| 111 | |
| 112 | for dir in std::env::split_paths(&path_var) { |
| 113 | let candidate = dir.join(binary_name); |
| 114 | if candidate.is_file() && is_executable(&candidate) { |
| 115 | return Ok(candidate); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | Err(format!("{} not found on PATH", binary_name)) |
| 120 | } |
| 121 | |
| 122 | /// Check whether a file is executable. |
| 123 | #[cfg(unix)] |
no test coverage detected