flodl_cli/util/
install_prompt.rs1use std::path::PathBuf;
11use std::process::Command;
12
13use crate::util::prompt;
14
15pub fn offer_global_install() {
20 let Some(home_os) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE"))
21 else {
22 return;
23 };
24 let target = PathBuf::from(home_os).join(".local/bin/fdl");
25
26 let current = match std::env::current_exe() {
27 Ok(p) => p,
28 Err(_) => return,
29 };
30
31 let current_canon = current.canonicalize().unwrap_or_else(|_| current.clone());
33 let target_canon = target.canonicalize().unwrap_or_else(|_| target.clone());
34 if current_canon == target_canon {
35 return;
36 }
37
38 if target.exists() {
41 return;
42 }
43
44 println!();
45 let msg = format!(
46 "Install fdl globally to {}?",
47 target.display()
48 );
49 if !prompt::ask_yn(&msg, true) {
50 println!(" (later: ./fdl install)");
51 return;
52 }
53
54 let status = Command::new(¤t).arg("install").status();
55 match status {
56 Ok(s) if s.success() => {}
57 _ => {
58 eprintln!("fdl install did not complete; rerun manually with `./fdl install`.");
59 }
60 }
61}