summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-06 10:56:30 +0200
committerfxqnlr <[email protected]>2024-09-06 10:56:30 +0200
commit3e1cb020d5449849b37874f91cadfa4a9c878747 (patch)
treec5503a137c77ac33c1e7ddfd4087cc994b51a43b /src/config.rs
downloadarbs-3e1cb020d5449849b37874f91cadfa4a9c878747.tar
arbs-3e1cb020d5449849b37874f91cadfa4a9c878747.tar.gz
arbs-3e1cb020d5449849b37874f91cadfa4a9c878747.zip
initial commit, can save index, no modification check
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}