fixed configuration location, added match case

This commit is contained in:
Wyatt J. Miller 2022-07-10 13:58:45 -04:00
parent 5a9b95f912
commit e4bd984d8c

View File

@ -18,10 +18,26 @@ 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 match env::consts::OS {
location.push("config.json".to_string()); // this case is currently untested
location.push("/etc/gt/config.json".to_string()); "windows" => {
location.push(format!("{}/.config/gt/config.json", home_dir_env)); location.push(String::from("config.json"));
location.push(String::from("{:?}/AppData/gt/config.json"))
},
// this case is currently untested
"macos" => {
location.push(String::from("config.json"));
},
"linux" => {
location.push(String::from("config.json"));
location.push(String::from("/etc/gt/config.json"));
location.push(format!("{:?}/.config/gt/config.json", home_dir_env));
},
_ => {
println!("Unsupported operating system! {:?} might cause some instabilities!", env::consts::OS);
location.push(String::from("config.json"));
}
}
for i in location { for i in location {
settings.merge(File::with_name(&i).required(false)).unwrap(); settings.merge(File::with_name(&i).required(false)).unwrap();
@ -35,25 +51,8 @@ impl Configuration {
} }
} }
#[cfg(target_os = "linux")] impl Default for Configuration {
fn set_location_linux(location: &mut Vec<String>, home: String) -> Vec<String> { fn default() -> Self {
location.push("config.json".to_string()); Self::new()
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()
} }