Struct boxxy::shell::Toolbox
[−]
[src]
pub struct Toolbox(_);
The set of registered commands.
Methods
impl Toolbox
[src]
fn empty() -> Toolbox
[src]
Create an empty toolbox.
use boxxy::Toolbox; let toolbox = Toolbox::empty();
fn new() -> Toolbox
[src]
Create a toolbox that contains the default builtin commands.
use boxxy::Toolbox; let toolbox = Toolbox::new();
fn get(&self, key: &str) -> Option<&Command>
[src]
Get a command by its name.
use boxxy::Toolbox; let toolbox = Toolbox::new(); println!("command: {:?}", toolbox.get("cat"));
fn keys(&self) -> Vec<String>
[src]
List available commands.
use boxxy::Toolbox; let toolbox = Toolbox::new(); println!("commands: {:?}", toolbox.keys());
fn insert<I: Into<String>>(&mut self, key: I, func: Command)
[src]
Insert a command into the toolbox.
use boxxy::{Toolbox, Command}; fn example(args: Vec<String>) -> Result<(), boxxy::Error> { println!("The world is your oyster! {:?}", args); Ok(()) } let mut toolbox = Toolbox::new(); toolbox.insert("example", Command::Native(example)); println!("commands: {:?}", toolbox.keys());
fn insert_many<I: Into<String>>(&mut self, commands: Vec<(I, Command)>)
[src]
Insert many commands into the toolbox.
use boxxy::{Toolbox, Command}; fn example1(_args: Vec<String>) -> Result<(), boxxy::Error> { println!("example1"); Ok(()) } fn example2(_args: Vec<String>) -> Result<(), boxxy::Error> { println!("example2"); Ok(()) } let mut toolbox = Toolbox::new(); toolbox.insert_many(vec![ ("example1", Command::Native(example1)), ("example2", Command::Native(example2)), ]); println!("commands: {:?}", toolbox.keys());
fn insert_many_native<I: Into<String>>(
&mut self,
commands: Vec<(I, NativeCommand)>
)
[src]
&mut self,
commands: Vec<(I, NativeCommand)>
)
Insert many NativeCommand
s into the toolbox.
use boxxy::Toolbox; fn example1(_args: Vec<String>) -> Result<(), boxxy::Error> { println!("example1"); Ok(()) } fn example2(_args: Vec<String>) -> Result<(), boxxy::Error> { println!("example2"); Ok(()) } let mut toolbox = Toolbox::new(); toolbox.insert_many_native(vec![ ("example1", example1), ("example2", example2), ]); println!("commands: {:?}", toolbox.keys());
fn with<I: Into<String>>(self, commands: Vec<(I, NativeCommand)>) -> Toolbox
[src]
Builder pattern to create a toolbox with custom commands.
use boxxy::Toolbox; fn example(args: Vec<String>) -> Result<(), boxxy::Error> { println!("The world is your oyster! {:?}", args); Ok(()) } let toolbox = Toolbox::new().with(vec![ ("example", example), ]); println!("commands: {:?}", toolbox.keys());