diff --git a/src/main.rs b/src/main.rs index 0cb9e8c..7dfccd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::{error::Error, path::PathBuf}; mod config { use std::{ + env, error::Error, fs, path::{Path, PathBuf}, @@ -35,7 +36,16 @@ mod config { /// Loads the configuration toml from a path into the Config struct. #[inline] pub fn new(path: PathBuf) -> Result> { - let yaml = fs::read_to_string(path)?; + let yaml = match fs::read_to_string(path) { + Ok(content) => content, + _ => match fs::read_to_string(format!( + "{}/hilsen/config.yaml", + env::var("XDG_CONFIG_HOME").unwrap() + )) { + Ok(content) => content, + _ => panic!(), + }, + }; let config = serde_yaml::from_str(&yaml)?; @@ -128,7 +138,7 @@ async fn main() -> Result<(), Box> { if let Some(config_file) = matches.get_one::("config") { config = config::Config::new(config_file.clone())?; } else { - panic!(); + config = config::Config::new("".into())?; } if matches.get_flag("showConfigParse") {