1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
mod describer;
mod detector;
mod downloader;
mod errors;
mod executor;
mod helpers;
mod installer;
mod manifest;
mod plugin;
mod resolver;
mod shimmer;
mod tool;
mod tools_config;
mod user_config;
mod verifier;

pub use async_trait::async_trait;
pub use describer::*;
pub use detector::*;
pub use downloader::*;
pub use errors::*;
pub use executor::*;
pub use helpers::*;
pub use installer::*;
pub use lenient_semver::Version;
pub use manifest::*;
pub use plugin::*;
pub use resolver::*;
pub use shimmer::*;
pub use starbase_styles::color;
pub use tool::*;
pub use tools_config::*;
pub use user_config::*;
pub use verifier::*;

use std::path::{Path, PathBuf};

pub struct Proto {
    pub bin_dir: PathBuf,
    pub plugins_dir: PathBuf,
    pub temp_dir: PathBuf,
    pub tools_dir: PathBuf,
    pub home_dir: PathBuf,
}

impl Proto {
    pub fn new() -> Result<Self, ProtoError> {
        let root = get_root()?;

        Ok(Proto {
            bin_dir: root.join("bin"),
            plugins_dir: root.join("plugins"),
            temp_dir: root.join("temp"),
            tools_dir: root.join("tools"),
            home_dir: get_home_dir()?,
        })
    }

    pub fn from(root: &Path) -> Self {
        Proto {
            bin_dir: root.join("bin"),
            plugins_dir: root.join("plugins"),
            temp_dir: root.join("temp"),
            tools_dir: root.join("tools"),
            home_dir: get_home_dir().expect("Missing home directory."),
        }
    }
}

impl AsRef<Proto> for Proto {
    fn as_ref(&self) -> &Proto {
        self
    }
}