feat: add cli ext event hooks example (#4935)

This commit is contained in:
Matthias Seitz
2023-10-06 20:05:03 +02:00
committed by GitHub
parent c825aafbc8
commit 36306ce916
6 changed files with 108 additions and 1 deletions

View File

@ -113,6 +113,15 @@ impl<Ext: RethCliExt> Cli<Ext> {
reth_tracing::init(layers);
Ok(guard.flatten())
}
/// Configures the given node extension.
pub fn with_node_extension<C>(mut self, conf: C) -> Self
where
C: Into<Ext::Node>,
{
self.command.set_node_extension(conf.into());
self
}
}
/// Convenience function for parsing CLI options, set up logging and run the chosen command.
@ -156,6 +165,17 @@ pub enum Commands<Ext: RethCliExt = ()> {
Recover(recover::Command),
}
impl<Ext: RethCliExt> Commands<Ext> {
/// Sets the node extension if it is the [NodeCommand](node::NodeCommand).
///
/// This is a noop if the command is not the [NodeCommand](node::NodeCommand).
pub fn set_node_extension(&mut self, ext: Ext::Node) {
if let Commands::Node(command) = self {
command.ext = ext
}
}
}
/// The log configuration.
#[derive(Debug, Args)]
#[command(next_help_heading = "Logging")]