use std::env;
use std::path::PathBuf;
use anyhow::Context;
use crate::config::DRIVER_ENV;
pub fn driver_path(driver_bin: &str) -> anyhow::Result<PathBuf> {
if let Some(explicit) = env::var_os(DRIVER_ENV) {
return Ok(PathBuf::from(explicit));
}
let file_name = format!("{driver_bin}{}", env::consts::EXE_SUFFIX);
let current =
env::current_exe().context("failed to locate the running cargo-cgp executable")?;
if let Some(dir) = current.parent() {
let sibling = dir.join(&file_name);
if sibling.is_file() {
return Ok(sibling);
}
}
Ok(PathBuf::from(file_name))
}