chiark / gitweb /
Config inspection: Make PrintConfigOpt type
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2023 20:49:46 +0000 (20:49 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 Jan 2023 02:12:41 +0000 (02:12 +0000)
This will let us hang more things on it

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

index 2f284c717ec182e83d3c81a2749108f6a7835d5e..0747a223bfc6bd53b6b70f37b071e1390f9972cf 100644 (file)
@@ -338,7 +338,8 @@ async fn main() {
   let opts = <Opts as clap::Parser>::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,))
   });
index 3a3643c9aecd4778aac996283502f865a3269824..621d06eea05b74c684c8fa36a3f1e90d8ef22f3c 100644 (file)
@@ -164,8 +164,8 @@ async fn async_main(opts: Opts, daemon: Option<Daemoniser>) {
   {
     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() {
       (||{
index 711ede7c08c16a472b6f2e2bd36ad72da566e29b..8960433f30c0e30544f7ff78896a0b6f3c996517 100644 (file)
@@ -118,15 +118,27 @@ impl InspectableConfig for InstanceConfig {
   }
 }
 
-#[throws(AE)]
-pub fn implement_print_config<'c, C: InspectableConfig + 'c>(
-  configs: impl Iterator<Item=&'c C>,
-  arg: &Option<String>,
-) {
+#[derive(Debug,Clone,Copy)]
+pub struct PrintConfigOpt<'a>(pub &'a Option<String>);
+
+impl PrintConfigOpt<'_> {
   #[throws(AE)]
-  pub fn print_one_config<'f>(
-    config: &dyn InspectableConfig,
+  pub fn implement<'c, C: InspectableConfig + 'c>(
+    self,
+    configs: impl Iterator<Item=&'c C>,
+  ) {
+    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 {
index c4ee088f1eca6bf716ebe7bbbf95d635e707591f..105734561e21b3cdca46d863bea2aad6a5cab409 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, 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;