From: Ian Jackson Date: Mon, 9 Jan 2023 19:07:52 +0000 (+0000) Subject: Config inspection: Move --print-config implementation into trait X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=580fe79ae15637f8fdea7e0c8b7e4323cb3573f2;p=hippotat.git Config inspection: Move --print-config implementation into trait Signed-off-by: Ian Jackson --- 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 {