infra to synthesize program options with config options
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
59efabbbc2
commit
2fb43dd38d
4 changed files with 16 additions and 5 deletions
|
@ -405,7 +405,7 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Initialize config
|
/// Initialize config
|
||||||
pub fn new(path: Option<PathBuf>) -> Result<Self> {
|
pub fn new(path: &Option<PathBuf>) -> Result<Self> {
|
||||||
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())
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use conduit::{Config, Result};
|
||||||
|
|
||||||
/// Commandline arguments
|
/// Commandline arguments
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -15,4 +16,13 @@ pub(crate) struct Args {
|
||||||
|
|
||||||
/// Parse commandline arguments into structured data
|
/// Parse commandline arguments into structured data
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn parse() -> Args { Args::parse() }
|
pub(super) fn parse() -> Args { Args::parse() }
|
||||||
|
|
||||||
|
/// Synthesize any command line options with configuration file options.
|
||||||
|
pub(crate) fn update(config: &mut Config, args: &Args) -> Result<()> {
|
||||||
|
// Indicate the admin console should be spawned automatically if the
|
||||||
|
// configuration file hasn't already.
|
||||||
|
config.admin_console_automatic |= args.console.unwrap_or(false);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ fn main() -> Result<(), Error> {
|
||||||
.build()
|
.build()
|
||||||
.expect("built runtime");
|
.expect("built runtime");
|
||||||
|
|
||||||
let server: Arc<Server> = Server::build(args, Some(runtime.handle()))?;
|
let server: Arc<Server> = Server::build(&args, Some(runtime.handle()))?;
|
||||||
runtime.spawn(signal::signal(server.clone()));
|
runtime.spawn(signal::signal(server.clone()));
|
||||||
runtime.block_on(async_main(&server))?;
|
runtime.block_on(async_main(&server))?;
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,9 @@ pub(crate) struct Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub(crate) fn build(args: Args, runtime: Option<&runtime::Handle>) -> Result<Arc<Self>, Error> {
|
pub(crate) fn build(args: &Args, runtime: Option<&runtime::Handle>) -> Result<Arc<Self>, Error> {
|
||||||
let config = Config::new(args.config)?;
|
let mut config = Config::new(&args.config)?;
|
||||||
|
crate::clap::update(&mut config, args)?;
|
||||||
|
|
||||||
#[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
Reference in a new issue