diff options
author | fxqnlr <[email protected]> | 2024-09-06 10:56:30 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-06 10:56:30 +0200 |
commit | 3e1cb020d5449849b37874f91cadfa4a9c878747 (patch) | |
tree | c5503a137c77ac33c1e7ddfd4087cc994b51a43b /src/config.rs | |
download | arbs-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.rs | 33 |
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 @@ | |||
1 | use config::{File, Map}; | ||
2 | use serde::{Deserialize, Serialize}; | ||
3 | |||
4 | #[derive(Debug, Serialize, Deserialize)] | ||
5 | #[serde(default)] | ||
6 | pub 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 | |||
13 | impl 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 | |||
24 | impl 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 | } | ||