A crate that provides a simple interface for executing commands from the user.
```rust use simpleshell::{Shell, Command, CommandError}; use ansiterm::{Color, Style};
fn version(_: &[String], _: &[Command]) -> Result<(), CommandError> { println!("v0.1.0"); Ok(()) }
fn help(: &[String], commands: &[Command]) -> Result<(), CommandError> { println!("{}", Color::Blue.paint("HELP")); commands.iter().foreach(|c| println!("{}: {}", Style::new().bold().paint(&c.name), c.description)); Ok(()) }
let commands = vec![ Command { name: "version".toowned(), description: "Returns the version of the software".toowned(), exec: Box::new(version), }, Command { name: "help".toowned(), description: "Prints out this help".toowned(), exec: Box::new(help), }, ];
let shell = Shell::new(None, commands); loop { if let Err(e) = shell.process(){ eprintln!("{}", e); } } ```
Results in:
$ shell> version
v0.1.0