diff options
author | FxQnLr <[email protected]> | 2024-02-26 12:43:35 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-02-26 12:43:35 +0100 |
commit | ffedfd00a46147b225c834187fc298e88e60d0c5 (patch) | |
tree | 655989e635a1a3a6ae9cf7bc393c59a3f8b4c25c | |
parent | 3a2dc1f2741f7bf4d72c1cbe0fd1993af157ceaa (diff) | |
download | webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar.gz webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.zip |
Closes #6. Should autodetect config dir
-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 | } |