Struct clapcmd::ClapCmd

source ·
pub struct ClapCmd<State = (), History = MemHistory>where
    State: Clone,
    History: History,{
    pub output: String,
    pub info: String,
    pub warn: String,
    pub error: String,
    pub success: String,
    pub async_output: Arc<Mutex<String>>,
    /* private fields */
}
Expand description

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

Fields§

§output: String
Available on crate feature test-runner only.

When test-runner feature is active, contains the output data from the previous command

§info: String
Available on crate feature test-runner only.

When test-runner feature is active, contains the info data from the previous command

§warn: String
Available on crate feature test-runner only.

When test-runner feature is active, contains the warn data from the previous command

§error: String
Available on crate feature test-runner only.

When test-runner feature is active, contains the error data from the previous command

§success: String
Available on crate feature test-runner only.

When test-runner feature is active, contains the success data from the previous command

§async_output: Arc<Mutex<String>>
Available on crate feature test-runner only.

When test-runner feature is active, contains the async_output data from the previous command

Implementations§

source§

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

source

pub fn with_state(state: State) -> Selfwhere State: Send + Sync + 'static,

Generate a default ClapCmd instance with the specified initial State

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 unset_state(&mut self)

Delete the internal state

source

pub fn get_state(&self) -> Option<&State>

Retrieve the current state from a callback

source

pub fn get_state_mut(&mut self) -> Option<&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 set_continuation_prompt(&mut self, continuation_prompt: &str)

Set the continuation 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 output(&mut self, output: impl Into<String>)

Print a standard message to stdout

source

pub fn warn(&mut self, output: impl Into<String>)

Print a warning to stdout

source

pub fn error(&mut self, output: impl Into<String>)

Print an error to stdout

source

pub fn success(&mut self, output: impl Into<String>)

Print a success message to stdout

source

pub fn info(&mut self, output: impl Into<String>)

Print an informational message to stdout

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(s) specified by the line read from the user

source

pub fn run_loop(&mut self)

Run the command loop until a callback returns Err(Box::new(clapcmd::errors::ExitError))

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 = (), History = MemHistory> !RefUnwindSafe for ClapCmd<State, History>

§

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

§

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

§

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

§

impl<State = (), History = MemHistory> !UnwindSafe for ClapCmd<State, History>

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.