summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-25 16:14:56 +0100
committerFxQnLr <[email protected]>2024-02-25 16:14:56 +0100
commit03bea24f9de698375033af92a08762446d0e20cc (patch)
tree71b696ddcdc14f36115155be7f287fc0cb43e16d /src/config.rs
parentcd73d51fba4a7d24b5ef12cb7d23054ab922cb67 (diff)
downloadwebol-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.rs30
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 @@
1use config::Config; 1use serde::Deserialize;
2use once_cell::sync::Lazy;
3 2
4pub static SETTINGS: Lazy<Config> = Lazy::new(setup); 3#[derive(Deserialize)]
5 4pub struct Config {
6fn 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)] 9impl 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}