1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::env;
use std::path::{Path, PathBuf};

pub const DEFAULT_CONFIG_FILE_NAME: &str = "default.toml";

pub fn get_wrangler_home_dir() -> Result<PathBuf, failure::Error> {
    let config_dir = if let Ok(value) = env::var("WRANGLER_HOME") {
        log::info!("Using $WRANGLER_HOME: {}", value);
        Path::new(&value).to_path_buf()
    } else {
        log::info!("No $WRANGLER_HOME detected, using $HOME");
        dirs::home_dir()
            .expect("Could not find home directory")
            .join(".wrangler")
    };
    Ok(config_dir)
}

pub fn get_global_config_path() -> Result<PathBuf, failure::Error> {
    let home_dir = get_wrangler_home_dir()?;
    let global_config_file = home_dir.join("config").join(DEFAULT_CONFIG_FILE_NAME);
    log::info!("Using global config file: {}", global_config_file.display());
    Ok(global_config_file)
}