Expand description
The Command trait, its descriptor, and the link-time registration slice.
A Command is an opinionated async fn(App) -> Result<()> bundled
with a small static descriptor (CommandSpec). Commands self-
register via a linkme distributed slice so no manual wiring is
needed when authoring new commands.
§Registration pattern
ⓘ
use rtb_app::command::{BUILTIN_COMMANDS, Command, CommandSpec};
use rtb_app::linkme::distributed_slice;
pub struct Deploy;
#[async_trait::async_trait]
impl Command for Deploy {
fn spec(&self) -> &CommandSpec {
static SPEC: CommandSpec = CommandSpec {
name: "deploy",
about: "Deploy the thing",
..CommandSpec::DEFAULT
};
&SPEC
}
async fn run(&self, _app: rtb_app::app::App) -> miette::Result<()> {
Ok(())
}
}
#[distributed_slice(BUILTIN_COMMANDS)]
fn __register_deploy() -> Box<dyn Command> { Box::new(Deploy) }rtb-cli::Application::run iterates BUILTIN_COMMANDS at startup,
filters by the runtime Features set, and registers each remaining
command with clap.
Structs§
- Command
Spec - Static descriptor of a
Command.
Statics§
- BUILTIN_
COMMANDS - Link-time registry of
Commandfactory functions. - BUILTIN_
PRERUN_ HOOKS - Link-time registry of
PreRunHooks run before command dispatch.
Traits§
- Command
- The contract every CLI subcommand implements.
Type Aliases§
- PreRun
Future - A boxed,
Sendfuture returned by aPreRunHook. - PreRun
Hook - A pre-run hook, invoked with the
Appbefore command dispatch.