summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock115
-rw-r--r--Cargo.toml3
-rw-r--r--src/config.rs30
-rw-r--r--src/main.rs17
4 files changed, 163 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3af2a9f..d3259dd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -53,6 +53,12 @@ dependencies = [
]
[[package]]
+name = "anyhow"
+version = "1.0.104"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
+
+[[package]]
name = "clap"
version = "4.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -99,12 +105,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
+name = "equivalent"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
+
+[[package]]
+name = "hashbrown"
+version = "0.17.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
+
+[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
+name = "indexmap"
+version = "2.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07aa2048142242915a31d35844fb311e0e53fcca590c3a0a40dcf1b841fa09eb"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -138,7 +166,49 @@ dependencies = [
name = "rss-aggregator"
version = "0.1.0"
dependencies = [
+ "anyhow",
"clap",
+ "serde",
+ "toml",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
+dependencies = [
+ "serde_core",
]
[[package]]
@@ -159,6 +229,45 @@ dependencies = [
]
[[package]]
+name = "toml"
+version = "1.1.5+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "12c0ba9680044b4ce98d391a62094047eada0d64860b80166c39f4a6b5640785"
+dependencies = [
+ "indexmap",
+ "serde_core",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_parser",
+ "toml_writer",
+ "winnow",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "1.1.1+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "toml_parser"
+version = "1.1.3+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56"
+dependencies = [
+ "winnow",
+]
+
+[[package]]
+name = "toml_writer"
+version = "1.1.2+spec-1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
+
+[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -184,3 +293,9 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
+
+[[package]]
+name = "winnow"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"
diff --git a/Cargo.toml b/Cargo.toml
index 798c321..ed82a07 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,4 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
+anyhow = "1.0.104"
clap = { version = "4.6.6", features = ["derive"] }
+serde = { version = "1.0.229", features = ["derive"] }
+toml = "1.1.5"
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..518a82a
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,30 @@
+use std::{fs::File, io::{Read, read_to_string}, path::Path};
+
+use serde::Deserialize;
+
+#[derive(Deserialize)]
+pub struct Config {
+}
+
+pub const DEFAULT_CONFIG_FILE_LOCATIONS: [&str; 1] = [
+ "/etc/rss-aggregator.toml",
+];
+
+impl Config {
+ pub fn parse_config_file_at_path(path: &str) -> anyhow::Result<Config> {
+ let path = Path::new(path);
+ let file = File::open(&path)?;
+ let contents = read_to_string(file)?;
+ Ok(toml::from_str(&contents)?)
+ }
+
+ pub fn find_config() -> Option<Config> {
+ for path in DEFAULT_CONFIG_FILE_LOCATIONS {
+ match Self::parse_config_file_at_path(path) {
+ Ok(config) => { return Some(config); },
+ Err(_) => {},
+ };
+ };
+ None
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 705b33b..b445285 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,24 @@
+mod config;
+
use clap::Parser;
+use crate::config::Config;
+
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
+ /// Path to the config file. If blank, searches default config locations.
+ #[arg(short = 'c', long = "config", default_value = "")]
+ config_file: String,
}
fn main() {
- let _args = Args::parse();
- println!("Hello, world!");
+ 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)),
+ path => Config::parse_config_file_at_path(&path).unwrap_or_else(|err|
+ panic!("Failed to parse config at {}. Error: {}", path, err)),
+ };
+ println!("Found config file.");
}