diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index a2a93a60..2989ba01 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -23,6 +23,7 @@ use std::path::PathBuf; use anyhow::Context; use clap::Clap; use mas_config::ConfigurationSection; +use tracing::trace; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; use self::{ @@ -57,8 +58,14 @@ enum Subcommand { #[derive(Clap, Debug)] struct RootCommand { /// Path to the configuration file - #[clap(short, long, global = true, default_value = "config.yaml")] - config: PathBuf, + #[clap( + short, + long, + global = true, + default_value = "config.yaml", + multiple_occurrences(true) + )] + config: Vec, #[clap(subcommand)] subcommand: Option, @@ -78,7 +85,7 @@ impl RootCommand { } fn load_config<'de, T: ConfigurationSection<'de>>(&self) -> anyhow::Result { - T::load_from_file(&self.config).context("could not load configuration") + T::load_from_files(&self.config).context("could not load configuration") } } @@ -105,5 +112,6 @@ async fn main() -> anyhow::Result<()> { let opts = RootCommand::parse(); // And run the command + trace!(?opts, "Running command"); opts.run().await } diff --git a/crates/config/src/util.rs b/crates/config/src/util.rs index b9fc9108..268cad10 100644 --- a/crates/config/src/util.rs +++ b/crates/config/src/util.rs @@ -56,15 +56,25 @@ pub trait ConfigurationSection<'a>: Sized + Deserialize<'a> + Serialize { .context("could not load configuration") } + /// Load configuration from a list of files and environment variables. + fn load_from_files

(paths: &[P]) -> Result + where + P: AsRef, + { + let base = Figment::new().merge(Env::prefixed("MAS_").split("_")); + + paths + .iter() + .fold(base, |f, path| f.merge(Yaml::file(path))) + .extract_inner(Self::path()) + } + /// Load configuration from a file and environment variables. fn load_from_file

(path: P) -> Result where P: AsRef, { - Figment::new() - .merge(Env::prefixed("MAS_").split("_")) - .merge(Yaml::file(path)) - .extract_inner(Self::path()) + Self::load_from_files(&[path]) } /// Generate config used in unit tests