summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-26 12:43:35 +0100
committerFxQnLr <[email protected]>2024-02-26 12:43:35 +0100
commitffedfd00a46147b225c834187fc298e88e60d0c5 (patch)
tree655989e635a1a3a6ae9cf7bc393c59a3f8b4c25c
parent3a2dc1f2741f7bf4d72c1cbe0fd1993af157ceaa (diff)
downloadwebol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar
webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar.gz
webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.zip
Closes #6. Should autodetect config dir
-rw-r--r--Cargo.toml2
-rw-r--r--src/config.rs19
2 files changed, 16 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4791c6c..36b08c5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,6 @@ indicatif = "0.17"
20reqwest = { version = "0.11", features = ["blocking"] } 20reqwest = { version = "0.11", features = ["blocking"] }
21serde = "1.0" 21serde = "1.0"
22serde_json = "1.0" 22serde_json = "1.0"
23thiserror = "1.0.57" 23thiserror = "1.0"
24tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] } 24tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] }
25tokio-tungstenite = "0.21" 25tokio-tungstenite = "0.21"
diff --git a/src/config.rs b/src/config.rs
index d28e111..769269c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -8,12 +8,23 @@ pub struct Config {
8 8
9impl Config { 9impl Config {
10 pub fn load() -> Result<Config, config::ConfigError> { 10 pub fn load() -> Result<Config, config::ConfigError> {
11 let builder = config::Config::builder() 11 let config_dir = dirs::config_dir();
12 .add_source(config::File::with_name("~/.config/webol-cli").required(false)) 12
13 let builder = config::Config::builder();
14
15 let builder = if let Some(conf) = config_dir {
16 let dir = conf.to_string_lossy();
17 builder.add_source(config::File::with_name(format!("{dir}/webol-cli").as_str()).required(false))
18 } else {
19 println!("!No config dir found");
20 builder
21 };
22
23 let build = builder
13 .add_source(config::File::with_name("webol-cli").required(false)) 24 .add_source(config::File::with_name("webol-cli").required(false))
14 .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) 25 .add_source(config::Environment::with_prefix("WEBOL_CLI").separator("_"))
15 .build()?; 26 .build()?;
16 27
17 builder.try_deserialize() 28 build.try_deserialize()
18 } 29 }
19} 30}