1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Load the config file from a environment variable

This commit is contained in:
Quentin Gliech
2022-03-11 17:03:28 +01:00
parent 3d3b14093c
commit c9f16ae781

View File

@ -49,13 +49,7 @@ enum Subcommand {
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
pub struct Options { pub struct Options {
/// Path to the configuration file /// Path to the configuration file
#[clap( #[clap(short, long, global = true, multiple_occurrences(true))]
short,
long,
global = true,
default_value = "config.yaml",
multiple_occurrences(true)
)]
config: Vec<PathBuf>, config: Vec<PathBuf>,
#[clap(subcommand)] #[clap(subcommand)]
@ -77,6 +71,12 @@ impl Options {
} }
pub fn load_config<'de, T: ConfigurationSection<'de>>(&self) -> anyhow::Result<T> { pub fn load_config<'de, T: ConfigurationSection<'de>>(&self) -> anyhow::Result<T> {
T::load_from_files(&self.config).context("could not load configuration") let configs = if self.config.is_empty() {
vec![std::env::var("MAS_CONFIG").map_or_else(|_| "config.yaml".into(), PathBuf::from)]
} else {
self.config.clone()
};
T::load_from_files(&configs).context("could not load configuration")
} }
} }