From 919fc40136aca94cb99441f78f7ca8c43e790748 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 10 Jan 2023 20:49:46 +0000 Subject: [PATCH] Config inspection: Make PrintConfigOpt type This will let us hang more things on it Signed-off-by: Ian Jackson --- client/client.rs | 3 ++- server/server.rs | 4 ++-- src/config.rs | 33 +++++++++++++++++++-------------- src/prelude.rs | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/client/client.rs b/client/client.rs index 2f284c7..0747a22 100644 --- a/client/client.rs +++ b/client/client.rs @@ -338,7 +338,8 @@ async fn main() { let opts = ::parse(); let (ics,) = config::startup("hippotat", LinkEnd::Client, &opts.config, &opts.log, |ics| { - implement_print_config(&mut ics.iter(), &opts.print_config)?; + PrintConfigOpt(&&opts.print_config) + .implement(&mut ics.iter(), )?; Ok((ics,)) }); diff --git a/server/server.rs b/server/server.rs index 3a3643c..621d06e 100644 --- a/server/server.rs +++ b/server/server.rs @@ -164,8 +164,8 @@ async fn async_main(opts: Opts, daemon: Option) { { let global_config = config::InstanceConfigGlobal::from(&ics); - implement_print_config(&mut iter::once(&global_config), - &opts.print_config)?; + PrintConfigOpt(&opts.print_config) + .implement(&mut iter::once(&global_config))?; if let Some(pidfile_path) = opts.pidfile.as_ref() { (||{ diff --git a/src/config.rs b/src/config.rs index 711ede7..8960433 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,15 +118,27 @@ impl InspectableConfig for InstanceConfig { } } -#[throws(AE)] -pub fn implement_print_config<'c, C: InspectableConfig + 'c>( - configs: impl Iterator, - arg: &Option, -) { +#[derive(Debug,Clone,Copy)] +pub struct PrintConfigOpt<'a>(pub &'a Option); + +impl PrintConfigOpt<'_> { #[throws(AE)] - pub fn print_one_config<'f>( - config: &dyn InspectableConfig, + pub fn implement<'c, C: InspectableConfig + 'c>( + self, + configs: impl Iterator, + ) { + if let Some(arg) = self.0 { + for config in configs { + Self::print_one_config(arg, config)?; + } + process::exit(0); + } + } + + #[throws(AE)] + fn print_one_config( arg: &str, + config: &dyn InspectableConfig, ) { let output = arg .split(',') @@ -142,13 +154,6 @@ pub fn implement_print_config<'c, C: InspectableConfig + 'c>( .join(" "); println!("{}", output); } - - if let Some(arg) = arg { - for config in configs { - print_one_config(config, arg)?; - } - process::exit(0); - } } pub trait InspectableConfigValue { diff --git a/src/prelude.rs b/src/prelude.rs index c4ee088..1057345 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -55,7 +55,7 @@ pub use eyre::eyre as anyhow; pub use eyre::WrapErr; pub use eyre::Error as AE; -pub use crate::config::{self, InstanceConfig, implement_print_config}; +pub use crate::config::{self, InstanceConfig, PrintConfigOpt}; pub use crate::config::{InspectableConfig, InspectableConfigValue}; pub use crate::config::{DisplayInspectable, U32Ext as _}; pub use crate::impl_inspectable_config_value; -- 2.30.2