improve path argument to Config::load and constructions
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
6e7c73336c
commit
1351d07735
2 changed files with 21 additions and 11 deletions
|
@ -4,7 +4,7 @@ pub mod proxy;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet, HashSet},
|
collections::{BTreeMap, BTreeSet, HashSet},
|
||||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use conduwuit_macros::config_example_generator;
|
use conduwuit_macros::config_example_generator;
|
||||||
|
@ -1797,14 +1797,17 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Pre-initialize config
|
/// Pre-initialize config
|
||||||
pub fn load(paths: Option<&[PathBuf]>) -> Result<Figment> {
|
pub fn load<'a, I>(paths: I) -> Result<Figment>
|
||||||
let paths_files = paths.into_iter().flatten().map(Toml::file);
|
where
|
||||||
|
I: Iterator<Item = &'a Path>,
|
||||||
|
{
|
||||||
let envs = [Env::var("CONDUIT_CONFIG"), Env::var("CONDUWUIT_CONFIG")];
|
let envs = [Env::var("CONDUIT_CONFIG"), Env::var("CONDUWUIT_CONFIG")];
|
||||||
let envs_files = envs.into_iter().flatten().map(Toml::file);
|
|
||||||
|
|
||||||
let config = envs_files
|
let config = envs
|
||||||
.chain(paths_files)
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.map(Toml::file)
|
||||||
|
.chain(paths.map(Toml::file))
|
||||||
.fold(Figment::new(), |config, file| config.merge(file.nested()))
|
.fold(Figment::new(), |config, file| config.merge(file.nested()))
|
||||||
.merge(Env::prefixed("CONDUIT_").global().split("__"))
|
.merge(Env::prefixed("CONDUIT_").global().split("__"))
|
||||||
.merge(Env::prefixed("CONDUWUIT_").global().split("__"));
|
.merge(Env::prefixed("CONDUWUIT_").global().split("__"));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::sync::Arc;
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
config::Config,
|
config::Config,
|
||||||
|
@ -35,9 +35,16 @@ impl Server {
|
||||||
) -> Result<Arc<Self>, Error> {
|
) -> Result<Arc<Self>, Error> {
|
||||||
let _runtime_guard = runtime.map(runtime::Handle::enter);
|
let _runtime_guard = runtime.map(runtime::Handle::enter);
|
||||||
|
|
||||||
let raw_config = Config::load(args.config.as_deref())?;
|
let config_paths = args
|
||||||
let raw_config = crate::clap::update(raw_config, args)?;
|
.config
|
||||||
let config = Config::new(&raw_config)?;
|
.as_deref()
|
||||||
|
.into_iter()
|
||||||
|
.flat_map(<[_]>::iter)
|
||||||
|
.map(PathBuf::as_path);
|
||||||
|
|
||||||
|
let config = Config::load(config_paths)
|
||||||
|
.and_then(|raw| crate::clap::update(raw, args))
|
||||||
|
.and_then(|raw| Config::new(&raw))?;
|
||||||
|
|
||||||
#[cfg(feature = "sentry_telemetry")]
|
#[cfg(feature = "sentry_telemetry")]
|
||||||
let sentry_guard = crate::sentry::init(&config);
|
let sentry_guard = crate::sentry::init(&config);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue