diff options
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 | } |