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 /src | |
parent | 3a2dc1f2741f7bf4d72c1cbe0fd1993af157ceaa (diff) | |
download | webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.tar.gz webol-cli-ffedfd00a46147b225c834187fc298e88e60d0c5.zip |
Closes #6. Should autodetect config dir
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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 | } |