infra to synthesize program options with config options

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-22 21:16:46 +00:00
parent 59efabbbc2
commit 2fb43dd38d
4 changed files with 16 additions and 5 deletions

View file

@ -405,7 +405,7 @@ const DEPRECATED_KEYS: &[&str; 9] = &[
impl 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") {
Figment::new()
.merge(Toml::file(config_file_env).nested())

View file

@ -3,6 +3,7 @@
use std::path::PathBuf;
use clap::Parser;
use conduit::{Config, Result};
/// Commandline arguments
#[derive(Parser, Debug)]
@ -15,4 +16,13 @@ pub(crate) struct Args {
/// Parse commandline arguments into structured data
#[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(())
}

View file

@ -33,7 +33,7 @@ fn main() -> Result<(), Error> {
.build()
.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.block_on(async_main(&server))?;

View file

@ -21,8 +21,9 @@ pub(crate) struct Server {
}
impl Server {
pub(crate) fn build(args: Args, runtime: Option<&runtime::Handle>) -> Result<Arc<Self>, Error> {
let config = Config::new(args.config)?;
pub(crate) fn build(args: &Args, runtime: Option<&runtime::Handle>) -> Result<Arc<Self>, Error> {
let mut config = Config::new(&args.config)?;
crate::clap::update(&mut config, args)?;
#[cfg(feature = "sentry_telemetry")]
let sentry_guard = crate::sentry::init(&config);