From ee0b8f79d9f03e90645cf11f2d71a74d3d59c56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Tue, 21 May 2024 21:32:32 +0200 Subject: [PATCH] feat: use XDG_CONFIG_HOME MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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") {