Crates.io | cmdr |
lib.rs | cmdr |
version | 0.3.12 |
source | src |
created_at | 2019-01-03 23:28:40.7469 |
updated_at | 2020-11-01 11:50:50.250007 |
description | Cmdr is a library for building line-oriented text-based user interfaces |
homepage | |
repository | https://github.com/mendelt/cmdr |
max_upload_size | |
id | 105331 |
size | 30,383 |
Cmdr is a library for building line-oriented text-based user interfaces. It lets you focus on writing the implementations of your commands while it handles user interaction, parsing etc.
Out of the box CMDR gives you;
To use CMDR you write the commands you want your user to interact with as functions on one or more Scope types. By implementing the scope trait cmdr can implement and execute your supplied commands. Implementing the Scope trait is as easy by using the supplied cmdr macro and annotating your commands with the cmd annotation to provide useful metadata on your commands. Doc strings in your command will be picked up automatically and used as help text.
use cmdr::*;
/// Example scope that implements two commands, greet and quit
struct GreeterScope {}
#[cmdr]
impl GreeterScope {
/// Cmdr command to greet someone. Takes one parameter and prints a greeting
#[cmd]
fn greet(&self, args: &[String]) -> CommandResult {
println!("Hello {}", args[0]);
Ok(Action::Done)
}
/// Cmdr command to quit the application by returning CommandResult::Quit
#[cmd]
fn quit(&self, _args: &[String]) -> CommandResult {
println!("Quitting");
Ok(Action::Quit)
}
}
/// Main function that creates the scope and starts a command loop for it
fn main() -> cmdr::Result<()> {
cmd_loop(&mut GreeterScope {})?;
Ok(())
}
version: 0.3.11
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.