summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs19
1 files changed, 14 insertions, 5 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(_) => {},
};