diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..947a5ad --- /dev/null +++ b/src/config.rs @@ -0,0 +1,34 @@ +use std::env; + +use config::File; +use serde::{Deserialize}; + +#[derive(Debug, Deserialize)] +pub struct Configuration { + pub api_token: String, + pub base_api: String, + pub base_url: String, + pub username: Option +} + +impl Configuration { + pub fn new() -> Configuration { + let home_dir_env = env::var("HOME").unwrap(); + let mut settings = config::Config::default(); + let mut location: Vec = Vec::new(); + + location.push("config.json".to_string()); + location.push("/etc/gt/config.json".to_string()); + location.push(format!("{}/.config/gt/config.json", home_dir_env)); + + for i in location { + settings.merge(File::with_name(&i) + .required(false)) + .unwrap(); + } + + let config = settings.try_into::().expect("Couldn't load config into gt!"); + + config + } +} \ No newline at end of file