From 6c8996a765a8714bf3fb67eefa08fbc260c88c90 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Fri, 4 Sep 2026 19:16:41 +0100 Subject: default config file location in --- src/config.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 518a82a..b812455 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,9 +6,18 @@ use serde::Deserialize; pub struct Config { } -pub const DEFAULT_CONFIG_FILE_LOCATIONS: [&str; 1] = [ - "/etc/rss-aggregator.toml", -]; +pub fn default_config_file_locations() -> Vec { + let mut default_config_file_locations = vec![ + String::from("/etc/rss-aggregator.toml"), + ]; + match dirs::config_dir().and_then(|config_dir| config_dir.into_string().ok()) { + Some(config_dir) => { + default_config_file_locations.push(format!("{config_dir}/rss-aggregator.toml")); + }, + _ => {}, + }; + default_config_file_locations +} impl Config { pub fn parse_config_file_at_path(path: &str) -> anyhow::Result { @@ -19,8 +28,8 @@ impl Config { } pub fn find_config() -> Option { - for path in DEFAULT_CONFIG_FILE_LOCATIONS { - match Self::parse_config_file_at_path(path) { + for path in default_config_file_locations() { + match Self::parse_config_file_at_path(&path) { Ok(config) => { return Some(config); }, Err(_) => {}, }; -- cgit v1.2.3