duct.rs
A Rust port of duct.py. Here's the crates.io package. A work in progress.
extern crate duct;
use sh;
A Rust port of duct.py. Here's the crates.io package. A work in progress.
#[macro_use(cmd)]
extern crate duct;
use duct::sh;
fn main() {
// Read the name of the current git branch.
let current_branch = sh("git symbolic-ref --short HEAD").read().unwrap();
assert_eq!(current_branch, "master");
// Log the current branch, with git taking over the terminal as usual.
cmd!("git", "log", current_branch).run().unwrap();
// Gratuitously pipe a bunch of commands together.
let result = sh("echo -n The future")
.then(sh("echo $HORRIFYING_ERROR >&2"))
.env("HORRIFYING_ERROR", "was then!")
.stderr_to_stdout()
.pipe(cmd!("sed", "s/was then/ is now/"))
.capture_stdout()
.run()
.unwrap();
assert_eq!(result.status, 0);
assert_eq!(result.stdout, b"The future is now!\n");
assert_eq!(result.stderr, b"");
}