pub struct ConsoleKernel { /* private fields */ }Expand description
The console kernel — registers and dispatches CLI commands.
Analogous to App\Console\Kernel in Laravel. Supports loading commands
from a closure, which mirrors the routes/console.php pattern.
§Example
use larastvel_core::console::{ConsoleKernel, Command};
use std::sync::Arc;
let app = larastvel_core::Application::new(None);
let kernel = app.console_kernel();
kernel.add_command(Arc::new(MyCommand));
kernel.call("my-command", &[]).await?;Implementations§
Source§impl ConsoleKernel
impl ConsoleKernel
Sourcepub fn new(app: Application) -> Self
pub fn new(app: Application) -> Self
Create a new kernel bound to the given application.
Sourcepub fn add_command(&self, cmd: Arc<dyn Command>)
pub fn add_command(&self, cmd: Arc<dyn Command>)
Register a command.
If a command with the same name() already exists it is overwritten.
Sourcepub fn add_commands(&self, cmds: Vec<Arc<dyn Command>>)
pub fn add_commands(&self, cmds: Vec<Arc<dyn Command>>)
Register multiple commands at once.
Sourcepub fn has_command(&self, name: &str) -> bool
pub fn has_command(&self, name: &str) -> bool
Returns true if a command with the given name has been registered.
Sourcepub fn command_count(&self) -> usize
pub fn command_count(&self) -> usize
Returns the number of registered commands.
Sourcepub fn command_names(&self) -> Vec<String>
pub fn command_names(&self) -> Vec<String>
Returns a list of all registered command names.
Sourcepub fn get_command(&self, name: &str) -> Option<Arc<dyn Command>>
pub fn get_command(&self, name: &str) -> Option<Arc<dyn Command>>
Returns the command with the given name, if registered.
Sourcepub fn load(&self, f: impl FnOnce(&Self))
pub fn load(&self, f: impl FnOnce(&Self))
Load commands via a closure — the Rust equivalent of defining
Artisan commands in routes/console.php.
The closure receives this kernel so commands can be registered
with add_command or
add_commands.
The closure is guaranteed to run at most once.
Sourcepub fn call(&self, name: &str, args: &[String]) -> Result<(), ConsoleError>
pub fn call(&self, name: &str, args: &[String]) -> Result<(), ConsoleError>
Execute a command by name with the given arguments.
Returns Ok(()) on success, or Err(message) on failure.
Sourcepub fn app(&self) -> &Application
pub fn app(&self) -> &Application
Return the underlying application.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConsoleKernel
impl RefUnwindSafe for ConsoleKernel
impl Send for ConsoleKernel
impl Sync for ConsoleKernel
impl Unpin for ConsoleKernel
impl UnsafeUnpin for ConsoleKernel
impl UnwindSafe for ConsoleKernel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Event for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> ⓘ
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> ⓘ
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