From fdac730c537a7e6ad57119112283d2eb55a570ad Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 20 Oct 2021 16:48:24 +0200 Subject: fix configuration not loading correctly on release builds --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 27 +++++++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd25dc2..e68d6e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,7 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "catinator" -version = "1.5.0" +version = "1.6.1" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 41fe6a0..da941b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "catinator" -version = "1.5.0" +version = "1.6.1" authors = ["Max Audron "] edition = "2018" diff --git a/src/config.rs b/src/config.rs index 1a88b95..4429184 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ use figment::{ value::{Dict, Map}, Error, Figment, Metadata, Profile, Provider, }; +use tracing::debug; #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)] pub struct Config { @@ -80,18 +81,32 @@ impl Config { pub fn figment() -> Figment { use figment::providers::Env; - let figment = Figment::new(); + let mut figment = Figment::new(); #[cfg(debug_assertions)] const PROFILE: &str = "debug"; #[cfg(not(debug_assertions))] const PROFILE: &str = "release"; - figment - .merge(Toml::file("config.toml").nested()) - .merge(Toml::file("config.debug.toml").nested()) - .merge(Env::prefixed("CATINATOR_").split('_')) - .select(PROFILE) + let config_file = if let Ok(path) = std::env::var("CATINATOR_CONFIG") { + path + } else { + "config.toml".to_string() + }; + + debug!("using config file: {}", config_file); + + figment = figment + .merge(Toml::file(config_file).nested()) + .merge(Env::prefixed("CATINATOR_").split('_')); + + #[cfg(debug_assertions)] + { + debug!("sourcing debug config"); + figment = figment.merge(Toml::file("config.debug.toml").nested()); + } + + figment.select(PROFILE) } } -- cgit v1.2.3