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

pub struct Toolbox(_);

The set of registered commands.

Methods

impl Toolbox
[src]

[src]

Create an empty toolbox.

use boxxy::Toolbox;

let toolbox = Toolbox::empty();

[src]

Create a toolbox that contains the default builtin commands.

use boxxy::Toolbox;

let toolbox = Toolbox::new();

[src]

Get a command by its name.

use boxxy::Toolbox;

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

[src]

List available commands.

use boxxy::Toolbox;

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

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

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

[src]

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

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