Expand description
A minimalistic shell for commands
§Example
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().for_each(|c| println!("{}: {}", Style::new().bold().paint(&c.name), c.description));
Ok(())
}
let commands = vec![
Command {
name: "version".to_owned(),
description: "Returns the version of the software".to_owned(),
exec: Box::new(version),
},
Command {
name: "help".to_owned(),
description: "Prints out this help".to_owned(),
exec: Box::new(help),
},
];
let shell = Shell::new(None, commands);
loop {
if let Err(e) = shell.process(){
eprintln!("{}", e);
}
}
// User Input:
// shell> version
// Output:
// v0.1.0
Structs§
- Command
- Represents an executable command
- Shell
- Represents the
Shell
that parses the user input into a command and executes it
Enums§
- Command
Error - Errors that may occur while processing a command. An error occurs if it was not found or an error occured while executing the command