summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs33
1 files changed, 33 insertions, 0 deletions
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 @@
1use config::{File, Map};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize)]
5#[serde(default)]
6pub struct Config {
7 pub root: String,
8 pub user: Vec<String>,
9 pub directories: Vec<String>,
10 pub custom_directories: Map<String, String>
11}
12
13impl Default for Config {
14 fn default() -> Self {
15 Self {
16 root: "/mnt/backup".to_string(),
17 user: vec![],
18 directories: vec![],
19 custom_directories: Map::new(),
20 }
21 }
22}
23
24impl Config {
25 pub fn load() -> Result<Self, config::ConfigError> {
26 let config = config::Config::builder()
27 .add_source(File::with_name("config.toml").required(false))
28 .add_source(config::Environment::with_prefix("FXBAUP").separator("_"))
29 .build()?;
30
31 config.try_deserialize()
32 }
33}