wrote functions that are os specific

This commit is contained in:
Wyatt J. Miller 2021-07-28 21:31:25 -04:00
parent e753a7bf52
commit ceb7557f76

View File

@ -18,6 +18,7 @@ impl Configuration {
let mut settings = config::Config::default(); let mut settings = config::Config::default();
let mut location: Vec<String> = Vec::new(); let mut location: Vec<String> = Vec::new();
// TODO: add condition for target os
location.push("config.json".to_string()); location.push("config.json".to_string());
location.push("/etc/gt/config.json".to_string()); location.push("/etc/gt/config.json".to_string());
location.push(format!("{}/.config/gt/config.json", home_dir_env)); location.push(format!("{}/.config/gt/config.json", home_dir_env));
@ -28,8 +29,42 @@ impl Configuration {
.unwrap(); .unwrap();
} }
let config = settings.try_into::<Configuration>().expect("Couldn't load config into gt!"); let config = settings
.try_into::<Configuration>()
.expect("Couldn't load config into gt!");
config config
} }
} }
#[cfg(target_os = "linux")]
fn set_location_linux(
location: &mut Vec<String>,
home: String
) -> Vec<String> {
location.push("config.json".to_string());
location.push("/etc/gt/config.json".to_string());
location.push(format!("{}/.config/gt/config.json", home));
location.to_vec()
}
#[cfg(target_os = "macos")]
fn set_location_macos(
location: &mut Vec<String>,
home: String
) -> Vec<String> {
location.push("config.json".to_string());
location.to_vec()
}
#[cfg(target_os = "windows")]
fn set_location_windows(
location: &mut Vec<String>,
home: String
) -> Vec<String> {
location.push("config.json".to_string());
location.to_vec()
}