pub struct CommandRegistry { /* private fields */ }Expand description
Maps a command name to the handler that runs it - built fresh by
whatever calls CommandRegistry::dispatch (typically the generated
app’s own main.rs, via routes::console::commands()), not a
process-wide static: exactly one process ever reads it, for exactly
as long as that one xr <command> invocation runs, so there’s no
cross-request sharing need the way larust-events’ listener registry
or larust_http::route’s named-route registry have.
Implementations§
Source§impl CommandRegistry
impl CommandRegistry
pub fn new() -> Self
Sourcepub fn register<C: Command>(self) -> Self
pub fn register<C: Command>(self) -> Self
Registers C under its own Command::NAME. Panics on a duplicate
name - a startup-time registration collision is a real programmer
bug (the shadowed command would silently never run again); failing
loudly and immediately here beats a confusing “why did xr report:posts just run the wrong thing” bug report later, the same
reasoning JobRegistry::register’s own duplicate check already
established for this codebase.
Sourcepub async fn dispatch(
&self,
name: &str,
args: &[String],
) -> Result<bool, AppError>
pub async fn dispatch( &self, name: &str, args: &[String], ) -> Result<bool, AppError>
Runs the named command with args, returning Ok(true) if a
command with that name was actually registered and run, or
Ok(false) if nothing matched. false, not an error - the
distinction lets a caller (main.rs’s own dispatch chain) fall
through to its own “unknown command” handling for a name that
matches neither a registered Command nor one of the framework’s
own fixed subcommands (migrate, queue:work, …), rather than
this crate having to know about those at all.
Sourcepub fn list(&self) -> Vec<CommandInfo>
pub fn list(&self) -> Vec<CommandInfo>
Every registered command’s name and description, sorted by name -
for xr command:list to print in a stable, predictable order
rather than HashMap’s own unspecified iteration order.