Skip to content
Snippets Groups Projects
Commit 2fb43dd3 authored by Jason Volk's avatar Jason Volk
Browse files

infra to synthesize program options with config options


Signed-off-by: default avatarJason Volk <jason@zemos.net>
parent 59efabbb
No related branches found
No related tags found
1 merge request!530de-global services
...@@ -405,7 +405,7 @@ struct ListeningAddr { ...@@ -405,7 +405,7 @@ struct ListeningAddr {
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 @@ ...@@ -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 { ...@@ -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> { ...@@ -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 { ...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment