Simple `which`-like lookup: search `$PATH` for an executable with the given name.
(binary_name: &str)
| 118 | /// Simple `which`-like lookup: search `$PATH` for an executable with |
| 119 | /// the given name. |
| 120 | fn which(binary_name: &str) -> Result<PathBuf, String> { |
| 121 | let path_var = std::env::var("PATH").map_err(|_| "PATH not set".to_string())?; |
| 122 | |
| 123 | for dir in std::env::split_paths(&path_var) { |
| 124 | let candidate = dir.join(binary_name); |
| 125 | if candidate.is_file() && is_executable(&candidate) { |
| 126 | return Ok(candidate); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | Err(format!("{} not found on PATH", binary_name)) |
| 131 | } |
| 132 | |
| 133 | /// Check whether a file is executable. |
| 134 | #[cfg(unix)] |
no test coverage detected