[][src]Crate cicada

Cicada is a bash-like Unix shell written in Rust.

If you would like to use cicada as a regular shell, please see details in its repository

Here is how to use cicada as a library:

Add cicada into Cargo.toml

[dependencies]
cicada = "0.8.0"

Use cicada functions

extern crate cicada;

fn main() {
    let tokens = cicada::cmd_to_tokens("echo 'hi yoo' | `which wc`");
    assert_eq!(tokens.len(), 4);

    assert_eq!(tokens[0].0, "");
    assert_eq!(tokens[0].1, "echo");

    assert_eq!(tokens[1].0, "'");
    assert_eq!(tokens[1].1, "hi yoo");

    assert_eq!(tokens[2].0, "");
    assert_eq!(tokens[2].1, "|");

    assert_eq!(tokens[3].0, "`");
    assert_eq!(tokens[3].1, "which wc");

    let out1 = cicada::run("ls Cargo.toml foo");
    assert_eq!(out1.status, 1);
    assert_eq!(out1.stdout, "Cargo.toml\n");
    assert_eq!(out1.stderr, "ls: foo: No such file or directory\n");

    let out2 = cicada::run("ls | wc");
    assert_eq!(out2.status, 0);
    assert_eq!(out2.stdout, "       4       4      33\n");
}

Structs

CommandResult

Functions

cmd_to_tokens

Parse a command to tokens.

run

Run a command or a pipeline.