pub trait AddCommandExt {
// Required methods
fn add_command<T>(&mut self) -> &mut Self
where T: Command + 'static;
fn has_command<T>(&self) -> bool
where T: Command + 'static;
}Expand description
Extension trait for AppBuilder to add command registration methods.
This trait provides convenient methods for registering commands with the application builder. Commands registered this way will be available in the CLI interface when the application is run.
Required Methods§
Sourcefn add_command<T>(&mut self) -> &mut Selfwhere
T: Command + 'static,
fn add_command<T>(&mut self) -> &mut Selfwhere
T: Command + 'static,
Registers a command with the application builder.
The command will be available as a subcommand in the CLI interface.
If this is the first command being added, a CommandRegistry will
be automatically created and added to the application.
§Type Parameters
T- The command type to register. Must implementCommand + 'static.
§Returns
Returns &mut Self for method chaining.
§Examples
use diode::{App, AppBuilder};
use diode_base::{Command, AddCommandExt};
use clap::Command as ClapCommand;
use std::process::ExitCode;
use std::sync::Arc;
struct MyCommand;
impl Command for MyCommand {
fn command() -> ClapCommand { ClapCommand::new("my-cmd") }
}
let app = App::builder()
.add_command::<MyCommand>()
.build()
.await?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".