diff options
| author | Joe Carstairs <me@joeac.net> | 2026-09-04 19:16:41 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-09-04 19:16:41 +0100 |
| commit | 6c8996a765a8714bf3fb67eefa08fbc260c88c90 (patch) | |
| tree | da00bdf0da34bda99678cdcc6d592b03fd0c79d6 | |
| parent | 5270c5c73fc9e843b922f1e12b81c3c78d7e8a26 (diff) | |
default config file location in
| -rw-r--r-- | Cargo.lock | 97 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/config.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 2 |
4 files changed, 113 insertions, 6 deletions
@@ -59,6 +59,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" [[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] name = "clap" version = "4.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -105,12 +111,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" [[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + +[[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "hashbrown" version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -139,12 +177,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "libredox" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d8f1ea3f21fd3405dcaf6c9b5c1630af9afc422d9073ea39c5f6d6c772e08ed" +dependencies = [ + "libc", +] + +[[package]] name = "once_cell_polyfill" version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] name = "proc-macro2" version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -163,11 +222,23 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] name = "rss-aggregator" version = "0.1.0" dependencies = [ "anyhow", "clap", + "dirs", "serde", "toml", ] @@ -229,6 +300,26 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "toml" version = "1.1.5+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -280,6 +371,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -6,5 +6,6 @@ edition = "2024" [dependencies] anyhow = "1.0.104" clap = { version = "4.6.6", features = ["derive"] } +dirs = "6.0.0" serde = { version = "1.0.229", features = ["derive"] } toml = "1.1.5" 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)), }; |
