#command #builder #buildable #rub #extension #execute #closures

commandext

A Command extension suitable for use in Rust Builders

8 releases

Uses old Rust 2015

0.1.0 Jan 23, 2016
0.0.7 Dec 28, 2015
0.0.6 Mar 30, 2015
0.0.4 Feb 4, 2015
0.0.3 Jan 25, 2015

#1 in #rub

Download history 119/week @ 2024-07-25 159/week @ 2024-08-01 71/week @ 2024-08-08 210/week @ 2024-08-15 46/week @ 2024-08-22 47/week @ 2024-08-29 69/week @ 2024-09-05 52/week @ 2024-09-12 61/week @ 2024-09-19 156/week @ 2024-09-26 45/week @ 2024-10-03 75/week @ 2024-10-10 90/week @ 2024-10-17 56/week @ 2024-10-24 59/week @ 2024-10-31 87/week @ 2024-11-07

324 downloads per month
Used in 13 crates (10 directly)

MIT/Apache

13KB
222 lines

commandext

A Command extension suitable for use by Rust Builders.

Version

Crates.io Build Status

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Defines the CommandExt type.

CommandExt wraps Command and enhances it.

A CommandExt is built similar to a Command. Supply the command name, add args, set enviroment variables, etc. The exec function takes a closure that executes the command and returns the given result T.

Examples

use commandext::{CommandExt,to_procout};

let mut cmd = CommandExt::new("echo");
cmd.env("DEBUG", "true");
cmd.arg("test");

let output = cmd.exec(to_procout());
// Execute "echo 'Testing Spawn'" via spawn and verify the exit code was 0.
// As a side effect, you would see 'Testing Spawn' on stdout.
use commandext::{CommandExt,to_res};

let res = CommandExt::new("echo").arg("Testing Spawn").exec(to_res());

assert_eq!(Ok(0), res);
// Exeute "echo test" via output and verify the output is indeed "test\n".
// In this case there is nothing on stdout.  The output is consumed here.
extern crate sodium_sys;
extern crate commandext;

use commandext::{CommandExt,to_procout};
use sodium_sys::crypto::utils::secmem;

fn main() {
    let cmd = CommandExt::new("echo").arg("test").exec(to_procout());
    let output = cmd.unwrap();

    assert_eq!(secmem::memcmp(&[116, 101, 115, 116, 10], &output.stdout[..]), 0);
}

Dependencies

~41KB