allow taking multiple --config arguments to "include"/merge more config files

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-09-20 16:22:29 -04:00
parent 6acdd0d947
commit 73afc1fd8f
2 changed files with 15 additions and 18 deletions

View file

@ -426,29 +426,26 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
impl Config { impl Config {
/// Pre-initialize config /// Pre-initialize config
pub fn load(path: &Option<PathBuf>) -> Result<Figment> { pub fn load(paths: &Option<Vec<PathBuf>>) -> Result<Figment> {
let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") { let raw_config = if let Some(config_file_env) = Env::var("CONDUIT_CONFIG") {
Figment::new() Figment::new().merge(Toml::file(config_file_env).nested())
.merge(Toml::file(config_file_env).nested())
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
} else if let Some(config_file_arg) = Env::var("CONDUWUIT_CONFIG") { } else if let Some(config_file_arg) = Env::var("CONDUWUIT_CONFIG") {
Figment::new() Figment::new().merge(Toml::file(config_file_arg).nested())
.merge(Toml::file(config_file_arg).nested()) } else if let Some(config_file_args) = paths {
.merge(Env::prefixed("CONDUIT_").global().split("__")) let mut figment = Figment::new();
.merge(Env::prefixed("CONDUWUIT_").global().split("__"))
} else if let Some(config_file_arg) = path { for config in config_file_args {
Figment::new() figment = figment.merge(Toml::file(config).nested());
.merge(Toml::file(config_file_arg).nested()) }
.merge(Env::prefixed("CONDUIT_").global().split("__"))
.merge(Env::prefixed("CONDUWUIT_").global().split("__")) figment
} else { } else {
Figment::new() 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 /// Finalize config

View file

@ -14,7 +14,7 @@ use conduit::{
pub(crate) struct Args { pub(crate) struct Args {
#[arg(short, long)] #[arg(short, long)]
/// Path to the config TOML file (optional) /// Path to the config TOML file (optional)
pub(crate) config: Option<PathBuf>, pub(crate) config: Option<Vec<PathBuf>>,
/// Override a configuration variable using TOML 'key=value' syntax /// Override a configuration variable using TOML 'key=value' syntax
#[arg(long, short('O'))] #[arg(long, short('O'))]