&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);
}
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);
}
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));
}
}
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;