chiark / gitweb /
Config inspection: Reorganise implement_print_config
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2023 00:34:15 +0000 (00:34 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 Jan 2023 02:12:41 +0000 (02:12 +0000)
We want this to be able to
 - handle out-of-course keys
 - do word splitting in the implementaton

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
client/client.rs
server/server.rs
src/config.rs
src/prelude.rs

index 0f3cbbf2b56273852214f3025bfc7cd9b4022e24..96476c8eec2b6b2ebf95a57009115cbf4e158e09 100644 (file)
@@ -332,7 +332,7 @@ async fn main() {
                                &opts.config, &opts.log, |ics| {
     if let Some(arg) = &opts.print_config {
       for ic in &ics {
-        ic.implement_print_config(arg)?;
+        implement_print_config(arg, &|k| ic.inspect_key(k))?;
       }
       process::exit(0);
     }
index ff69b0ba6dbb459183bcb6c064fe103627874b9a..0b9ffedc7f1fd5c76948721c688fe4854118f639 100644 (file)
@@ -161,7 +161,7 @@ async fn async_main(opts: Opts, daemon: Option<Daemoniser>) {
     let global_config = config::InstanceConfigGlobal::from(&ics);
 
     if let Some(arg) = &opts.print_config {
-      global_config.implement_print_config(arg)?;
+      implement_print_config(arg, &|k| global_config.inspect_key(k))?;
       process::exit(0);
     }
 
index 1ecc4794fc012835c0c024940c2673ce4290e414..fff0546e6b40dc94845fc771f34ab035e2c25365 100644 (file)
@@ -93,18 +93,17 @@ pub struct Opts {
 pub trait InspectableConfig {
   fn inspect_key(&self, field: &'_ str)
                  -> Option<&dyn InspectableConfigValue>;
+}
 
-  #[throws(AE)]
-  fn implement_print_config(&self, key: &str) where Self: Sized {
-    #[throws(AE)]
-    fn inner(self_: &dyn InspectableConfig, key: &str) {
-      if let Some(inspectable) = self_.inspect_key(key) {
-        println!("{}", DisplayInspectable(inspectable));
-      } else {
-        throw!(anyhow!("unknown config key {:?}", key));
-      }
-    }
-    inner(self, key)?;
+#[throws(AE)]
+pub fn implement_print_config<'f>(
+  key: &str,
+  inspect_key: &dyn Fn(&str) -> Option<&'f dyn InspectableConfigValue>
+) {
+  if let Some(inspectable) = inspect_key(key) {
+    println!("{}", DisplayInspectable(inspectable));
+  } else {
+    throw!(anyhow!("unknown config key {:?}", key));
   }
 }
 
index e38c3d5585b3eefc98a6ea0e2298f4558e7bd170..c4ee088f1eca6bf716ebe7bbbf95d635e707591f 100644 (file)
@@ -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};
+pub use crate::config::{self, InstanceConfig, implement_print_config};
 pub use crate::config::{InspectableConfig, InspectableConfigValue};
 pub use crate::config::{DisplayInspectable, U32Ext as _};
 pub use crate::impl_inspectable_config_value;