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").is_some());
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.
#[macro_use] extern crate boxxy; use boxxy::{Toolbox, Command}; fn example(sh: &mut boxxy::Shell, args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "The world is your oyster! {:?}", args); Ok(()) } fn main() { 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.
#[macro_use] extern crate boxxy; use boxxy::{Toolbox, Command}; fn example1(sh: &mut boxxy::Shell, _args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "example1"); Ok(()) } fn example2(sh: &mut boxxy::Shell, _args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "example2"); Ok(()) } fn main() { 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.
#[macro_use] extern crate boxxy; use boxxy::Toolbox; fn example1(sh: &mut boxxy::Shell, _args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "example1"); Ok(()) } fn example2(sh: &mut boxxy::Shell, _args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "example2"); Ok(()) } fn main() { 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.
#[macro_use] extern crate boxxy; use boxxy::Toolbox; fn example(sh: &mut boxxy::Shell, args: Vec<String>) -> Result<(), boxxy::Error> { shprintln!(sh, "The world is your oyster! {:?}", args); Ok(()) } fn main() { let toolbox = Toolbox::new().with(vec![ ("example", example), ]); println!("commands: {:?}", toolbox.keys()); }