use std::path::{Path, PathBuf};
use par_term_acp::agents::resolve_binary_in_path;
pub fn resolve_par_term_binary(
explicit: Option<&Path>,
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
if let Some(path) = explicit {
return Ok(path.to_path_buf());
}
if let Ok(current) = std::env::current_exe()
&& let Some(dir) = current.parent()
{
let candidate = dir.join(if cfg!(windows) {
"par-term.exe"
} else {
"par-term"
});
if candidate.is_file() {
return Ok(candidate);
}
}
if let Some(path) = resolve_binary_in_path("par-term") {
return Ok(path);
}
Err("Could not find `par-term` binary. Pass --par-term-bin /path/to/par-term".into())
}