summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs19
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
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}