From 73afc1fd8f40ce9f546d7c7d097b54b1fc14ed82 Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 20 Sep 2024 16:22:29 -0400 Subject: [PATCH] allow taking multiple `--config` arguments to "include"/merge more config files Signed-off-by: strawberry --- src/core/config/mod.rs | 31 ++++++++++++++----------------- src/main/clap.rs | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 47ed0d60..9b5405b9 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -426,29 +426,26 @@ const DEPRECATED_KEYS: &[&str; 9] = &[ impl Config { /// Pre-initialize config - pub fn load(path: &Option) -> Result { + pub fn load(paths: &Option>) -> Result { let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") { - Figment::new() - .merge(Toml::file(config_file_env).nested()) - .merge(Env::prefixed("CONDUIT_").global().split("__")) - .merge(Env::prefixed("CONDUWUIT_").global().split("__")) + Figment::new().merge(Toml::file(config_file_env).nested()) } else if let Some(config_file_arg) = Env::var("CONDUWUIT_CONFIG") { - Figment::new() - .merge(Toml::file(config_file_arg).nested()) - .merge(Env::prefixed("CONDUIT_").global().split("__")) - .merge(Env::prefixed("CONDUWUIT_").global().split("__")) - } else if let Some(config_file_arg) = path { - Figment::new() - .merge(Toml::file(config_file_arg).nested()) - .merge(Env::prefixed("CONDUIT_").global().split("__")) - .merge(Env::prefixed("CONDUWUIT_").global().split("__")) + Figment::new().merge(Toml::file(config_file_arg).nested()) + } else if let Some(config_file_args) = paths { + let mut figment = Figment::new(); + + for config in config_file_args { + figment = figment.merge(Toml::file(config).nested()); + } + + figment } else { Figment::new() - .merge(Env::prefixed("CONDUIT_").global().split("__")) - .merge(Env::prefixed("CONDUWUIT_").global().split("__")) }; - Ok(raw_config) + Ok(raw_config + .merge(Env::prefixed("CONDUIT_").global().split("__")) + .merge(Env::prefixed("CONDUWUIT_").global().split("__"))) } /// Finalize config diff --git a/src/main/clap.rs b/src/main/clap.rs index 3af0be02..86b9fbd6 100644 --- a/src/main/clap.rs +++ b/src/main/clap.rs @@ -14,7 +14,7 @@ use conduit::{ pub(crate) struct Args { #[arg(short, long)] /// Path to the config TOML file (optional) - pub(crate) config: Option, + pub(crate) config: Option>, /// Override a configuration variable using TOML 'key=value' syntax #[arg(long, short('O'))]