diff options
| author | Max Audron <audron@cocaine.farm> | 2021-10-20 16:48:24 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-10-20 16:49:07 +0200 |
| commit | fdac730c537a7e6ad57119112283d2eb55a570ad (patch) | |
| tree | 32bdb849a69a23070289b870c3b22c7b68271f79 /src/config.rs | |
| parent | replace sedregex crate (diff) | |
fix configuration not loading correctly on release builds
Diffstat (limited to '')
| -rw-r--r-- | src/config.rs | 27 |
1 files changed, 21 insertions, 6 deletions
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) } } |
