pub struct CommandRegistry { /* private fields */ }Expand description
Registry of slash commands for an agent.
Provides a builder-style API for configuring which commands are available.
§Example
ⓘ
use agent_core::tui::commands::{
CommandRegistry, CustomCommand, CommandResult,
HelpCommand, ClearCommand, ThemesCommand,
};
// Start with defaults and customize
let commands = CommandRegistry::with_defaults()
.add(CustomCommand::new("deploy", "Deploy the app", |args, ctx| {
CommandResult::Message(format!("Deploying to {}...", args))
}))
.remove("quit") // Disable quit command
.build();
// Or build from scratch
let commands = CommandRegistry::new()
.add(HelpCommand)
.add(ClearCommand)
.add(ThemesCommand)
.build();Implementations§
Source§impl CommandRegistry
impl CommandRegistry
Sourcepub fn new() -> CommandRegistry
pub fn new() -> CommandRegistry
Create an empty registry with no commands.
Sourcepub fn with_defaults() -> CommandRegistry
pub fn with_defaults() -> CommandRegistry
Create a registry with the default commands.
Default commands include: help, clear, compact, themes, sessions, status, version, new-session, and quit.
Sourcepub fn add<C>(self, command: C) -> CommandRegistrywhere
C: SlashCommand + 'static,
pub fn add<C>(self, command: C) -> CommandRegistrywhere
C: SlashCommand + 'static,
Sourcepub fn add_boxed(self, command: Box<dyn SlashCommand>) -> CommandRegistry
pub fn add_boxed(self, command: Box<dyn SlashCommand>) -> CommandRegistry
Add a boxed command to the registry.
Use this when you already have a Box<dyn SlashCommand>.
Sourcepub fn remove(self, name: &str) -> CommandRegistry
pub fn remove(self, name: &str) -> CommandRegistry
Sourcepub fn build(self) -> Vec<Box<dyn SlashCommand>>
pub fn build(self) -> Vec<Box<dyn SlashCommand>>
Build into the final command list.
Consumes the registry and returns the commands.
Sourcepub fn commands(&self) -> &[Box<dyn SlashCommand>]
pub fn commands(&self) -> &[Box<dyn SlashCommand>]
Get commands as a slice (for inspection without consuming).
Trait Implementations§
Source§impl Default for CommandRegistry
impl Default for CommandRegistry
Source§fn default() -> CommandRegistry
fn default() -> CommandRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CommandRegistry
impl !RefUnwindSafe for CommandRegistry
impl Send for CommandRegistry
impl Sync for CommandRegistry
impl Unpin for CommandRegistry
impl !UnwindSafe for CommandRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more