easy_install/
env.rs

1use std::path::PathBuf;
2
3use crud_path::{add_github_path, is_github};
4
5pub const IS_WINDOWS: bool = cfg!(target_os = "windows");
6
7pub fn add_to_path(dir: &str) {
8    if crud_path::has_path(dir) {
9        return;
10    }
11
12    if is_github() {
13        add_github_path(dir);
14    }
15
16    if let Some(sh) = crud_path::add_path(dir) {
17        println!("Successfully added {dir} to {sh}'s $PATH");
18    } else {
19        println!("You need to add {dir} to your $PATH");
20    }
21}
22
23// #[cfg(not(target_os = "windows"))]
24// pub fn get_install_dir() -> PathBuf {
25//     use std::str::FromStr;
26//     let home = PathBuf::from_str(if is_admin::is_admin() {
27//         "/usr/bin"
28//     } else {
29//         "/usr/local/bin"
30//     })
31//     .unwrap();
32
33//     if !home.exists() {
34//         std::fs::create_dir(&home).expect("Failed to create_dir home_dir");
35//     }
36//     home
37// }
38
39// #[cfg(target_os = "windows")]
40pub fn get_install_dir() -> PathBuf {
41    let mut home = dirs::home_dir().expect("Failed to get home_dir");
42    home.push(".easy-install");
43
44    if !home.exists() {
45        std::fs::create_dir_all(&home).expect("Failed to create_dir home_dir");
46    }
47    let home_str = home.to_str().expect("Failed to get home_dir string");
48    add_to_path(home_str);
49    home
50}