referrerpolicy=no-referrer-when-downgrade
polkadot_omni_node_lib::extra_subcommand

Trait ExtraSubcommand

Source
pub trait ExtraSubcommand: Subcommand {
    // Required method
    fn handle(self, cfg: &RunConfig) -> Result<()>;
}
Expand description

A trait for injecting and handling additional CLI subcommands in a composable way.

This trait allows downstream crates using polkadot-omni-node-lib to plug in their own custom subcommands without having to modify the main CLI definition. This is especially useful for parachain node binaries that want to define optional utilities.

§Implementing a Custom Extra Command

To create your own subcommand:

  1. Define the subcommand using [clap::Subcommand].
  2. Implement this trait for it.
  3. Use it when running the node via run_with_custom_cli::<CliConfig, YourExtraCommand>(run_config)

§Minimal Example:

use clap::Parser; use polkadot_omni_node_lib::{ExtraSubcommand, RunConfig};

#[derive(Debug, Clone, Subcommand)] pub enum ExtraCmd { NewCmd, }

impl ExtraSubcommand for ExtraCmd {

fn handle(_cmd: ExtraCmd, _config: &RunConfig) -> sc_cli::Result<()> { println!(“Hello from Extra!”); Ok(()) } }

To use this in a binary:

let config = RunConfig::new(…); run_with_custom_cli::<CliConfig, ExtraCmd>(config)?;

Running it:

$ your-binary new-cmd
Hello from Extra!

§Supporting Multiple Subcommands

You can compose multiple extra commands via an enum. Just derive [clap::Subcommand] and match over the variants in handle.

#[derive(Debug, clap::Parser)] pub enum MyExtras { Foo(FooCmd), Bar(BarCmd), }

impl ExtraSubcommand for MyExtras {

fn handle(cmd: Self, config: &RunConfig) -> sc_cli::Result<()> { match cmd { MyExtras::Foo(foo) => { … } MyExtras::Bar(bar) => { … } } Ok(()) } } Trait implemented by a set of optional sub‑commands**.

Required Methods§

Source

fn handle(self, cfg: &RunConfig) -> Result<()>

Handle the command once it’s been parsed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§