use std::path::PathBuf;
use std::process::Command;
use crate::util::prompt;
pub fn offer_global_install() {
let Some(home_os) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE"))
else {
return;
};
let target = PathBuf::from(home_os).join(".local/bin/fdl");
let current = match std::env::current_exe() {
Ok(p) => p,
Err(_) => return,
};
let current_canon = current.canonicalize().unwrap_or_else(|_| current.clone());
let target_canon = target.canonicalize().unwrap_or_else(|_| target.clone());
if current_canon == target_canon {
return;
}
if target.exists() {
return;
}
println!();
let msg = format!(
"Install fdl globally to {}?",
target.display()
);
if !prompt::ask_yn(&msg, true) {
println!(" (later: ./fdl install)");
return;
}
let status = Command::new(¤t).arg("install").status();
match status {
Ok(s) if s.success() => {}
_ => {
eprintln!("fdl install did not complete; rerun manually with `./fdl install`.");
}
}
}