pub struct ClapCmd<State = (), History = MemHistory>{
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: Stringtest-runner only.When test-runner feature is active, contains the output data from the previous command
info: Stringtest-runner only.When test-runner feature is active, contains the info data from the previous command
warn: Stringtest-runner only.When test-runner feature is active, contains the warn data from the previous command
error: Stringtest-runner only.When test-runner feature is active, contains the error data from the previous command
success: Stringtest-runner only.When test-runner feature is active, contains the success data from the previous command
async_output: Arc<Mutex<String>>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,
impl<State> ClapCmd<State>where
State: Clone,
Sourcepub fn with_state(state: State) -> Self
pub fn with_state(state: State) -> Self
Generate a default ClapCmd instance with the specified initial State
Sourcepub fn builder() -> ClapCmdBuilder
pub fn builder() -> ClapCmdBuilder
Generate a ClapCmdBuilder object used mainly to expose rustyline settings
Sourcepub fn unset_state(&mut self)
pub fn unset_state(&mut self)
Delete the internal state
Sourcepub fn get_state_mut(&mut self) -> Option<&mut State>
pub fn get_state_mut(&mut self) -> Option<&mut State>
Retrieve a mutable reference to the current state from a callback
Sourcepub fn set_prompt(&mut self, prompt: &str)
pub fn set_prompt(&mut self, prompt: &str)
Set the current prompt
Sourcepub fn set_continuation_prompt(&mut self, continuation_prompt: &str)
pub fn set_continuation_prompt(&mut self, continuation_prompt: &str)
Set the continuation prompt
Sourcepub fn has_command(&self, command: &str) -> bool
pub fn has_command(&self, command: &str) -> bool
Checks if a given &str is connected to a command
Sourcepub fn add_command(&mut self, callback: impl Callback<State>, command: Command)
pub fn add_command(&mut self, callback: impl Callback<State>, command: Command)
Adds the specified command to the default group
Sourcepub fn remove_command(&mut self, command: &str)
pub fn remove_command(&mut self, command: &str)
Removes the command distinguished by the string command
Sourcepub fn group(name: &str) -> HandlerGroup<State>
pub fn group(name: &str) -> HandlerGroup<State>
Creates a new group that can be loaded an unloaded
Sourcepub fn unnamed_group() -> HandlerGroup<State>
pub fn unnamed_group() -> HandlerGroup<State>
Creates a new unnamed group that can be loaded an unloaded
Sourcepub fn add_group(&mut self, groups: &HandlerGroup<State>)
pub fn add_group(&mut self, groups: &HandlerGroup<State>)
Adds all the commands in a group
Sourcepub fn remove_group(&mut self, groups: &HandlerGroup<State>)
pub fn remove_group(&mut self, groups: &HandlerGroup<State>)
Removes all the commands in a group
Sourcepub fn get_async_writer(&mut self) -> Result<impl Write, Box<dyn Error>>
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
Sourcepub fn read_line(&mut self, prompt: &str) -> Option<String>
pub fn read_line(&mut self, prompt: &str) -> Option<String>
Creates a prompt and reads a single line from the user
Sourcepub fn one_cmd(&mut self, line: &str) -> ClapCmdResult
pub fn one_cmd(&mut self, line: &str) -> ClapCmdResult
Executes the appropriate command(s) specified by the line read from the user