pub struct CommandRegistry { /* private fields */ }Expand description
Registry for commands and optional alias/prefix routing.
§Example
use modcli::loader::CommandRegistry;
use modcli::command::Command;
struct Echo;
impl Command for Echo {
fn name(&self) -> &str { "echo" }
fn execute(&self, args: &[String]) { println!("{}", args.join(" ")) }
}
let mut reg = CommandRegistry::new();
reg.register(Box::new(Echo));
reg.execute("echo", &["hi".into()]);Implementations§
Source§impl CommandRegistry
impl CommandRegistry
Sourcepub fn set_prefix(&mut self, prefix: &str)
pub fn set_prefix(&mut self, prefix: &str)
Sets the command prefix
Sets an optional prefix used for routing commands of the form prefix:cmd.
Sourcepub fn get_prefix(&self) -> &str
pub fn get_prefix(&self) -> &str
Gets the command prefix Returns the configured prefix (empty string if not set).
Sourcepub fn get(&self, name: &str) -> Option<&dyn Command>
pub fn get(&self, name: &str) -> Option<&dyn Command>
Gets a command by name Gets a command by its primary name.
Sourcepub fn register(&mut self, cmd: Box<dyn Command>)
pub fn register(&mut self, cmd: Box<dyn Command>)
Gets a command by name with prefix Registers a command and records its aliases for reverse lookup.
Sourcepub fn all(&self) -> impl Iterator<Item = &Box<dyn Command>>
pub fn all(&self) -> impl Iterator<Item = &Box<dyn Command>>
Returns all registered commands (read-only) Returns an iterator over all registered commands.
Sourcepub fn load_plugins(&mut self, path: &str)
pub fn load_plugins(&mut self, path: &str)
Registers a command with an alias
Sourcepub fn execute(&self, cmd: &str, args: &[String])
pub fn execute(&self, cmd: &str, args: &[String])
Resolves and executes a command by name or alias, with optional prefix routing.
pub fn load_internal_commands(&mut self)
pub fn load_from(&mut self, source: Box<dyn CommandSource>)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn load_custom_commands(&mut self)
Trait Implementations§
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