Skip to main content

HandlerCli

Struct HandlerCli 

Source
pub struct HandlerCli { /* private fields */ }
Expand description

A registry-based Cli implementation that dispatches command lines to registered Handlers keyed by their verb.

Implementations§

Source§

impl HandlerCli

Source

pub fn new() -> Self

Creates a new, empty handler registry.

Source

pub fn collect(&self) -> Vec<Arc<dyn Handler>>

Returns all currently registered handlers.

Source

pub fn get(&self, name: &str) -> Option<Arc<dyn Handler>>

Returns the handler registered under the given verb, if any.

Source

pub fn register<T, H>(&self, ctx: &Arc<T>, handler: H)
where T: Context + Sized, H: Handler + Send + Sync + 'static,

Registers a handler by value under its verb, if its condition is met in the given context.

Source

pub fn register_arc<T, H>(&self, ctx: &Arc<T>, handler: &Arc<H>)
where T: Context + Sized, H: Handler + Send + Sync + 'static,

Registers an already-Arc-wrapped handler under its verb, if its condition is met in the given context.

Source

pub fn unregister(&self, name: &str) -> Option<Arc<dyn Handler>>

Removes and returns the handler registered under the given verb, if any.

Source

pub fn clear(&self) -> Result<()>

Removes all registered handlers.

Source

pub async fn start<T>(&self, ctx: &Arc<T>) -> Result<()>
where T: Context + Sized,

Invokes Handler::start on every registered handler.

Source

pub async fn stop<T>(&self, ctx: &Arc<T>) -> Result<()>
where T: Context + Sized,

Invokes the stop lifecycle on every registered handler.

Source

pub async fn execute<T>(&self, ctx: &Arc<T>, cmd: &str) -> Result<()>
where T: Context + Sized,

Parses the command line and dispatches it to the matching handler, returning Error::CommandNotFound if no handler matches the verb.

Source

pub async fn complete<T>( &self, ctx: &Arc<T>, cmd: &str, ) -> Result<Option<Vec<String>>>
where T: Context + Sized,

Returns completion candidates for the command line by delegating to the matching handler, or Error::CommandNotFound if no handler matches.

Trait Implementations§

Source§

impl Default for HandlerCli

Source§

fn default() -> HandlerCli

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more