feat: use XDG_CONFIG_HOME

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-05-21 21:32:32 +02:00
parent a96ddb2879
commit ee0b8f79d9
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE

View file

@ -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<Self, Box<dyn Error>> {
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<dyn Error>> {
if let Some(config_file) = matches.get_one::<PathBuf>("config") {
config = config::Config::new(config_file.clone())?;
} else {
panic!();
config = config::Config::new("".into())?;
}
if matches.get_flag("showConfigParse") {