diff options
author | FxQnLr <[email protected]> | 2024-02-25 16:14:56 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-02-25 16:14:56 +0100 |
commit | 03bea24f9de698375033af92a08762446d0e20cc (patch) | |
tree | 71b696ddcdc14f36115155be7f287fc0cb43e16d /src/config.rs | |
parent | cd73d51fba4a7d24b5ef12cb7d23054ab922cb67 (diff) | |
download | webol-cli-03bea24f9de698375033af92a08762446d0e20cc.tar webol-cli-03bea24f9de698375033af92a08762446d0e20cc.tar.gz webol-cli-03bea24f9de698375033af92a08762446d0e20cc.zip |
Closes #2. Config and setup stuff
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/config.rs b/src/config.rs index 9a9e44b..78795a3 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -1,19 +1,19 @@ | |||
1 | use config::Config; | 1 | use serde::Deserialize; |
2 | use once_cell::sync::Lazy; | ||
3 | 2 | ||
4 | pub static SETTINGS: Lazy<Config> = Lazy::new(setup); | 3 | #[derive(Deserialize)] |
5 | 4 | pub struct Config { | |
6 | fn setup() -> Config { | 5 | pub apikey: String, |
7 | #[cfg(not(debug_assertions))] | 6 | pub server: String, |
8 | let builder = Config::builder().add_source(config::File::with_name( | 7 | } |
9 | format!("{}/webol-cli.toml", dirs::config_dir().unwrap().to_string_lossy()).as_str(), | ||
10 | )); | ||
11 | 8 | ||
12 | #[cfg(debug_assertions)] | 9 | impl Config { |
13 | let builder = Config::builder().add_source(config::File::with_name("webol-cli.toml")); | 10 | pub fn load() -> Result<Config, config::ConfigError> { |
11 | let builder = config::Config::builder() | ||
12 | .add_source(config::File::with_name("~/.config/webol-cli.toml")) | ||
13 | .add_source(config::File::with_name("webol-cli.toml")) | ||
14 | .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) | ||
15 | .build()?; | ||
14 | 16 | ||
15 | builder | 17 | builder.try_deserialize() |
16 | .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) | 18 | } |
17 | .build() | ||
18 | .unwrap() | ||
19 | } | 19 | } |