From d911a855f7a5db9e41c10aedb0a0d20bc783c391 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 10 Jan 2023 20:54:46 +0000 Subject: [PATCH] Config inspection: Allow printing multiple instances Signed-off-by: Ian Jackson --- server/server.rs | 15 +++++++++++++-- src/config.rs | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/server.rs b/server/server.rs index 621d06e..50caa58 100644 --- a/server/server.rs +++ b/server/server.rs @@ -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, } @@ -164,8 +168,15 @@ async fn async_main(opts: Opts, daemon: Option) { { 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() { (||{ diff --git a/src/config.rs b/src/config.rs index ce63ce1..378d958 100644 --- a/src/config.rs +++ b/src/config.rs @@ -135,6 +135,10 @@ impl PrintConfigOpt<'_> { } } + pub fn keys(&self) -> impl Iterator { + self.0.as_ref().map(|arg| Self::split(arg)).into_iter().flatten() + } + fn split(arg: &str) -> impl Iterator { arg.split(',') } #[throws(AE)] -- 2.30.2