From 3e1cb020d5449849b37874f91cadfa4a9c878747 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 6 Sep 2024 10:56:30 +0200 Subject: initial commit, can save index, no modification check --- src/config.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..625118a --- /dev/null +++ b/src/config.rs @@ -0,0 +1,33 @@ +use config::{File, Map}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(default)] +pub struct Config { + pub root: String, + pub user: Vec, + pub directories: Vec, + pub custom_directories: Map +} + +impl Default for Config { + fn default() -> Self { + Self { + root: "/mnt/backup".to_string(), + user: vec![], + directories: vec![], + custom_directories: Map::new(), + } + } +} + +impl Config { + pub fn load() -> Result { + let config = config::Config::builder() + .add_source(File::with_name("config.toml").required(false)) + .add_source(config::Environment::with_prefix("FXBAUP").separator("_")) + .build()?; + + config.try_deserialize() + } +} -- cgit v1.2.3