Skip to main content

CliSubcommand

Trait CliSubcommand 

Source
pub trait CliSubcommand {
    // Required methods
    fn cli_command() -> Command;
    fn cli_dispatch(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>>;

    // Provided methods
    fn cli_manual_nodes(&self, _prefix: &str) -> Vec<CliManualNode> { ... }
    fn cli_dispatch_async<'a>(
        &'a self,
        matches: &'a ArgMatches,
    ) -> impl Future<Output = Result<(), Box<dyn Error>>> + 'a { ... }
}
Expand description

Trait for types that can be mounted as CLI subcommand groups.

Implemented automatically by #[cli] on an impl block. Allows nested composition: a parent CLI can mount a child’s commands as a subcommand group.

Required Methods§

Source

fn cli_command() -> Command

Build the clap Command tree for this type’s subcommands.

Source

fn cli_dispatch(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>>

Dispatch a matched subcommand to the appropriate method.

Provided Methods§

Source

fn cli_manual_nodes(&self, _prefix: &str) -> Vec<CliManualNode>

Collect the manual (whole-subtree reference) nodes for this type.

prefix is the command path of this node from the root of the invoked subtree (empty at the invocation root). Each leaf appends one node; each mount point recurses into its child type with an extended prefix.

The default returns an empty vec so hand-written CliSubcommand impls keep compiling; #[cli] always overrides it.

Source

fn cli_dispatch_async<'a>( &'a self, matches: &'a ArgMatches, ) -> impl Future<Output = Result<(), Box<dyn Error>>> + 'a

Dispatch a matched subcommand asynchronously.

Awaits the dispatched method directly without creating an internal runtime. Used by cli_run_async to support user-provided async runtimes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§