babash

Crates.iobabash
lib.rsbabash
version0.2.0
sourcesrc
created_at2020-12-30 12:35:14.895311
updated_at2021-02-02 10:02:10.94014
descriptionAn tiny wrapper around `std::process::Command`
homepage
repositoryhttps://github.com/imbolc/babash
max_upload_size
id329224
size10,072
Imbolc (imbolc)

documentation

README

babash

An tiny wrapper around std::process::Command sacrificing performance for simplicity.

  • works on both linux and windows
  • assumes an utf-8 environment
  • logs all commands and responses with proper levels

Example

fn main() -> std::io::Result<()> {
    stderrlog::new().verbosity(4).init().unwrap();
    let r = babash::call("foo")?; // doesn't check for exit status
    assert_eq!(r.code, Some(127));
    babash::ensure_call("bar")?; // produces an error on an bad exit status
    Ok(())
}

produces the following logging output:

INFO - Calling: foo
DEBUG - Response {
    command: "foo",
    code: Some(
        127,
    ),
    success: false,
    stdout: "",
    stderr: "sh: 1: foo: not found\n",
}
INFO - Calling: bar
ERROR - Response {
    command: "bar",
    code: Some(
        127,
    ),
    success: false,
    stdout: "",
    stderr: "sh: 1: bar: not found\n",
}
Error: Custom { kind: Other, error: "Unsuccessful call: Response {\n    command: \"bar\",\n    code: Some(\n
  127,\n    ),\n    success: false,\n    stdout: \"\",\n    stderr: \"sh: 1: bar: not found\\n\",\n}" }
Commit count: 4

cargo fmt