Struct boxxy::shell::Toolbox[][src]

pub struct Toolbox(_);

The set of registered commands.

Methods

impl Toolbox
[src]

Create an empty toolbox.

use boxxy::Toolbox;

let toolbox = Toolbox::empty();

Create a toolbox that contains the default builtin commands.

use boxxy::Toolbox;

let toolbox = Toolbox::new();

Get a command by its name.

use boxxy::Toolbox;

let toolbox = Toolbox::new();
println!("command: {:?}", toolbox.get("cat").is_some());

List available commands.

use boxxy::Toolbox;

let toolbox = Toolbox::new();
println!("commands: {:?}", toolbox.keys());

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());
}

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());
}

Insert many NativeCommands 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());
}

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());
}

Trait Implementations

impl Default for Toolbox
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl Send for Toolbox

impl Sync for Toolbox