Struct clapcmd::ClapCmd

source ·
pub struct ClapCmd<State = ()>where
    State: Clone + Default,{ /* private fields */ }
Expand description

An interactive CLI interface, holding state and responsible for acquiring user input and assigning tasks to callback functions.

Implementations§

source§

impl<State> ClapCmd<State>where State: Clone + Default,

source

pub fn builder() -> ClapCmdBuilder

Generate a ClapCmdBuilder object used mainly to expose rustyline settings

source

pub fn set_state(&mut self, state: State)

Set the internal state that is provided to callbacks

source

pub fn get_state(&self) -> &State

Retrieve the current state from a callback

source

pub fn get_state_mut(&mut self) -> &mut State

Retrieve a mutable reference to the current state from a callback

source

pub fn set_prompt(&mut self, prompt: &str)

Set the current prompt

source

pub fn has_command(&self, command: &str) -> bool

Checks if a given &str is connected to a command

source

pub fn add_command(&mut self, callback: impl Callback<State>, command: Command)

Adds the specified command to the default group

source

pub fn remove_command(&mut self, command: &str)

Removes the command distinguished by the string command

source

pub fn group(name: &str) -> HandlerGroup<State>

Creates a new group that can be loaded an unloaded

source

pub fn unnamed_group() -> HandlerGroup<State>

Creates a new unnamed group that can be loaded an unloaded

source

pub fn add_group(&mut self, groups: &HandlerGroup<State>)

Adds all the commands in a group

source

pub fn remove_group(&mut self, groups: &HandlerGroup<State>)

Removes all the commands in a group

source

pub fn get_async_writer(&mut self) -> Result<impl Write, Box<dyn Error>>

Returns a thread-safe Write object that can be used to asyncronously write output to stdout without interferring with the promptline

source

pub fn read_line(&mut self, prompt: &str) -> Option<String>

Creates a prompt and reads a single line from the user

source

pub fn one_cmd(&mut self, line: &str) -> ClapCmdResult

Executes the appropriate command specified by the line read from the user

source

pub fn run_loop(&mut self)

Run the command loop until a callback returns false

Trait Implementations§

source§

impl<State> Default for ClapCmd<State>where State: Clone + Default + Send + Sync + 'static,

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<State = ()> !RefUnwindSafe for ClapCmd<State>

§

impl<State> Send for ClapCmd<State>where State: Send,

§

impl<State> Sync for ClapCmd<State>where State: Sync,

§

impl<State> Unpin for ClapCmd<State>where State: Unpin,

§

impl<State = ()> !UnwindSafe for ClapCmd<State>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.