diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 2 |
2 files changed, 15 insertions, 6 deletions
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<String> { + 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<Config> { @@ -19,8 +28,8 @@ impl Config { } pub fn find_config() -> Option<Config> { - 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(_) => {}, }; diff --git a/src/main.rs b/src/main.rs index b445285..e56726a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ fn main() { let args = Args::parse(); let _config = match args.config_file.as_str() { "" => Config::find_config().unwrap_or_else(|| - panic!("Failed to find config. Paths searched: {:#?}", config::DEFAULT_CONFIG_FILE_LOCATIONS)), + panic!("Failed to find config. Paths searched: {:#?}", config::default_config_file_locations())), path => Config::parse_config_file_at_path(&path).unwrap_or_else(|err| panic!("Failed to parse config at {}. Error: {}", path, err)), }; |
