chiark / gitweb /
Config inspection: Allow printing multiple instances
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2023 20:54:46 +0000 (20:54 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 Jan 2023 02:12:41 +0000 (02:12 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
server/server.rs
src/config.rs

index 621d06eea05b74c684c8fa36a3f1e90d8ef22f3c..50caa58e7306389ad4aa79a89c16e793ca69e43c 100644 (file)
@@ -40,6 +40,10 @@ pub struct Opts {
   /// Argument is (comma-separated) list of config keys;
   /// values will be printed space-separated.
   /// The key `pretty` dumps the whole config in a pretty debug format.
+  ///
+  /// If none of the specified config keys are client-specific,
+  /// only one line will be printed.  Otherwise the output will
+  /// have one line per client association.
   #[clap(long)]
   print_config: Option<String>,
 }
@@ -164,8 +168,15 @@ async fn async_main(opts: Opts, daemon: Option<Daemoniser>) {
   {
     let global_config = config::InstanceConfigGlobal::from(&ics);
 
-    PrintConfigOpt(&opts.print_config)
-      .implement(&mut iter::once(&global_config))?;
+    {
+      let pc = PrintConfigOpt(&opts.print_config);
+
+      if pc.keys().all(|k| global_config.inspect_key(k).is_some()) {
+        pc.implement(&mut iter::once(&global_config))?;
+      } else {
+        pc.implement(&mut ics.iter())?;
+      }
+    }
 
     if let Some(pidfile_path) = opts.pidfile.as_ref() {
       (||{
index ce63ce10d26deaa154431180f74b18bd2fcc9eb6..378d9588b8567532cf36d9708fd1212c194e3d46 100644 (file)
@@ -135,6 +135,10 @@ impl PrintConfigOpt<'_> {
     }
   }
 
+  pub fn keys(&self) -> impl Iterator<Item=&str> {
+    self.0.as_ref().map(|arg| Self::split(arg)).into_iter().flatten()
+  }
+
   fn split(arg: &str) -> impl Iterator<Item=&str> { arg.split(',') }
 
   #[throws(AE)]