From: Ian Jackson Date: Tue, 10 Jan 2023 01:41:27 +0000 (+0000) Subject: Config inspection: Move process::exit call X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=e39e149d153960c31cb65adc6ed9cfa4a8c4d0de;p=hippotat.git Config inspection: Move process::exit call Signed-off-by: Ian Jackson --- diff --git a/client/client.rs b/client/client.rs index b7d9d1e..0d4a53c 100644 --- a/client/client.rs +++ b/client/client.rs @@ -343,15 +343,14 @@ async fn main() { } process::exit(0); } - if let Some(arg) = &opts.print_config { - implement_print_config(&mut ics.iter(), arg, &|ic, k| Some(match k { - "link" => &ic.link, - "server" => &ic.link.server, - "client" => &ic.link.client, - k => return ic.inspect_key(k), - }))?; - process::exit(0); - } + + implement_print_config(&mut ics.iter(), &opts.print_config, + &|ic, k| Some(match k { + "link" => &ic.link, + "server" => &ic.link.server, + "client" => &ic.link.client, + k => return ic.inspect_key(k), + }))?; Ok((ics,)) }); diff --git a/server/server.rs b/server/server.rs index 15ba532..0f240fb 100644 --- a/server/server.rs +++ b/server/server.rs @@ -160,11 +160,8 @@ async fn async_main(opts: Opts, daemon: Option) { { let global_config = config::InstanceConfigGlobal::from(&ics); - if let Some(arg) = &opts.print_config { - implement_print_config(&mut iter::once(&global_config), - arg, &|_,__| None)?; - process::exit(0); - } + implement_print_config(&mut iter::once(&global_config), + &opts.print_config, &|_,__| None)?; if let Some(pidfile_path) = opts.pidfile.as_ref() { (||{ diff --git a/src/config.rs b/src/config.rs index eab8815..6db3c12 100644 --- a/src/config.rs +++ b/src/config.rs @@ -98,7 +98,7 @@ pub trait InspectableConfig: Debug { #[throws(AE)] pub fn implement_print_config<'c, C: InspectableConfig>( configs: impl Iterator, - arg: &str, + arg: &Option, extra_key: &dyn Fn(&'c C, &str) -> Option<&'c dyn InspectableConfigValue> ) { #[throws(AE)] @@ -120,8 +120,11 @@ pub fn implement_print_config<'c, C: InspectableConfig>( println!("{}", output); } - for config in configs { - print_one_config(config, arg, &|k| extra_key(config, k))?; + if let Some(arg) = arg { + for config in configs { + print_one_config(config, arg, &|k| extra_key(config, k))?; + } + process::exit(0); } }