mxsh 0.1.0

Embeddable POSIX-style shell parser and runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use mxsh::ShellBuilder;
use mxsh::embed::{StdioConfig, VariableAttributes};
use mxsh::runtime::testing::{InMemoryRuntime, StringStdioOut};

fn main() {
    let stdout = StringStdioOut::new();
    let mut shell = ShellBuilder::new()
        .env("GREETING", "hello", VariableAttributes::EXPORT)
        .stdio(StdioConfig {
            stdout: stdout.fd(),
            ..StdioConfig::default()
        })
        .build(InMemoryRuntime::new())
        .expect("shell should build");
    let result = shell.run("echo \"$GREETING embedded shell\"");
    assert_eq!(result.status, 0);
    assert_eq!(stdout.collect(), "hello embedded shell\n");
}