diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/config.rs | 19 |
2 files changed, 16 insertions, 5 deletions
@@ -20,6 +20,6 @@ indicatif = "0.17" | |||
20 | reqwest = { version = "0.11", features = ["blocking"] } | 20 | reqwest = { version = "0.11", features = ["blocking"] } |
21 | serde = "1.0" | 21 | serde = "1.0" |
22 | serde_json = "1.0" | 22 | serde_json = "1.0" |
23 | thiserror = "1.0.57" | 23 | thiserror = "1.0" |
24 | tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] } | 24 | tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] } |
25 | tokio-tungstenite = "0.21" | 25 | tokio-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 | ||
9 | impl Config { | 9 | impl 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 | } |