From 580fe79ae15637f8fdea7e0c8b7e4323cb3573f2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 9 Jan 2023 19:07:52 +0000 Subject: [PATCH] Config inspection: Move --print-config implementation into trait Signed-off-by: Ian Jackson --- server/server.rs | 10 +++------- src/config.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/server/server.rs b/server/server.rs index 46bc7da..ff69b0b 100644 --- a/server/server.rs +++ b/server/server.rs @@ -160,13 +160,9 @@ async fn async_main(opts: Opts, daemon: Option) { { let global_config = config::InstanceConfigGlobal::from(&ics); - if let Some(key) = opts.print_config.as_ref() { - if let Some(inspectable) = global_config.inspect_key(key) { - println!("{}", DisplayInspectable(inspectable)); - process::exit(0); - } else { - throw!(anyhow!("unknown config key {:?}", key)); - } + if let Some(arg) = &opts.print_config { + global_config.implement_print_config(arg)?; + process::exit(0); } if let Some(pidfile_path) = opts.pidfile.as_ref() { diff --git a/src/config.rs b/src/config.rs index 7cc9adf..13605d5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -93,6 +93,15 @@ pub struct Opts { pub trait InspectableConfig { fn inspect_key(&self, field: &'_ str) -> Option<&dyn InspectableConfigValue>; + + #[throws(AE)] + fn implement_print_config(&self, key: &str) { + if let Some(inspectable) = self.inspect_key(key) { + println!("{}", DisplayInspectable(inspectable)); + } else { + throw!(anyhow!("unknown config key {:?}", key)); + } + } } pub trait InspectableConfigValue { -- 2.30.2