summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-26 15:50:00 +0100
committerGitHub <[email protected]>2024-02-26 15:50:00 +0100
commit31a57425a76cae121c5d8ef5b0f2442ca6a9ee61 (patch)
tree19151fea3c1548d6298c0fb819e2a776d9aca74a /src/config.rs
parent0967f44161e972ff1a8482fd168897a3b183bae3 (diff)
parentffedfd00a46147b225c834187fc298e88e60d0c5 (diff)
downloadwebol-cli-31a57425a76cae121c5d8ef5b0f2442ca6a9ee61.tar
webol-cli-31a57425a76cae121c5d8ef5b0f2442ca6a9ee61.tar.gz
webol-cli-31a57425a76cae121c5d8ef5b0f2442ca6a9ee61.zip
Merge pull request #7 from FxQnLr/webol-dev-9
Webol dev 9
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs
index 9a9e44b..769269c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,19 +1,30 @@
1use config::Config; 1use serde::Deserialize;
2use once_cell::sync::Lazy;
3 2
4pub static SETTINGS: Lazy<Config> = Lazy::new(setup); 3#[derive(Deserialize)]
4pub struct Config {
5 pub apikey: String,
6 pub server: String,
7}
8
9impl Config {
10 pub fn load() -> Result<Config, config::ConfigError> {
11 let config_dir = dirs::config_dir();
12
13 let builder = config::Config::builder();
5 14
6fn setup() -> Config { 15 let builder = if let Some(conf) = config_dir {
7 #[cfg(not(debug_assertions))] 16 let dir = conf.to_string_lossy();
8 let builder = Config::builder().add_source(config::File::with_name( 17 builder.add_source(config::File::with_name(format!("{dir}/webol-cli").as_str()).required(false))
9 format!("{}/webol-cli.toml", dirs::config_dir().unwrap().to_string_lossy()).as_str(), 18 } else {
10 )); 19 println!("!No config dir found");
20 builder
21 };
11 22
12 #[cfg(debug_assertions)] 23 let build = builder
13 let builder = Config::builder().add_source(config::File::with_name("webol-cli.toml")); 24 .add_source(config::File::with_name("webol-cli").required(false))
25 .add_source(config::Environment::with_prefix("WEBOL_CLI").separator("_"))
26 .build()?;
14 27
15 builder 28 build.try_deserialize()
16 .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) 29 }
17 .build()
18 .unwrap()
19} 30}