mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-03-14 18:55:37 +00:00
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::{
|
||||
collections::{BTreeMap, BTreeSet, HashSet},
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use conduwuit_macros::config_example_generator;
|
||||
|
@ -1797,14 +1797,17 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
|
|||
|
||||
impl Config {
|
||||
/// Pre-initialize config
|
||||
pub fn load(paths: Option<&[PathBuf]>) -> Result<Figment> {
|
||||
let paths_files = paths.into_iter().flatten().map(Toml::file);
|
||||
|
||||
pub fn load<'a, I>(paths: I) -> Result<Figment>
|
||||
where
|
||||
I: Iterator<Item = &'a Path>,
|
||||
{
|
||||
let envs = [Env::var("CONDUIT_CONFIG"), Env::var("CONDUWUIT_CONFIG")];
|
||||
let envs_files = envs.into_iter().flatten().map(Toml::file);
|
||||
|
||||
let config = envs_files
|
||||
.chain(paths_files)
|
||||
let config = envs
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(Toml::file)
|
||||
.chain(paths.map(Toml::file))
|
||||
.fold(Figment::new(), |config, file| config.merge(file.nested()))
|
||||
.merge(Env::prefixed("CONDUIT_").global().split("__"))
|
||||
.merge(Env::prefixed("CONDUWUIT_").global().split("__"));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use conduwuit::{
|
||||
config::Config,
|
||||
|
@ -35,9 +35,16 @@ impl Server {
|
|||
) -> Result<Arc<Self>, Error> {
|
||||
let _runtime_guard = runtime.map(runtime::Handle::enter);
|
||||
|
||||
let raw_config = Config::load(args.config.as_deref())?;
|
||||
let raw_config = crate::clap::update(raw_config, args)?;
|
||||
let config = Config::new(&raw_config)?;
|
||||
let config_paths = args
|
||||
.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")]
|
||||
let sentry_guard = crate::sentry::init(&config);
|
||||
|
|
Loading…
Add table
Reference in a new issue