From ffedfd00a46147b225c834187fc298e88e60d0c5 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 26 Feb 2024 12:43:35 +0100 Subject: Closes #6. Should autodetect config dir --- src/config.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') 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 { impl Config { pub fn load() -> Result { - let builder = config::Config::builder() - .add_source(config::File::with_name("~/.config/webol-cli").required(false)) + let config_dir = dirs::config_dir(); + + let builder = config::Config::builder(); + + let builder = if let Some(conf) = config_dir { + let dir = conf.to_string_lossy(); + builder.add_source(config::File::with_name(format!("{dir}/webol-cli").as_str()).required(false)) + } else { + println!("!No config dir found"); + builder + }; + + let build = builder .add_source(config::File::with_name("webol-cli").required(false)) - .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) + .add_source(config::Environment::with_prefix("WEBOL_CLI").separator("_")) .build()?; - builder.try_deserialize() + build.try_deserialize() } } -- cgit v1.2.3