2021-07-20 15:07:55 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-07-20 23:41:46 +05:30
|
|
|
#[macro_export]
|
|
|
|
macro_rules! args {
|
|
|
|
( $( $arg: expr ),* ) => {
|
|
|
|
{
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
let args = [$( OsStr::new($arg) ),*];
|
|
|
|
args
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-20 15:07:55 +05:30
|
|
|
// Returns stdout. The command must return zero.
|
2021-10-11 16:37:26 +05:30
|
|
|
pub fn run_ok(command: duct::Expression) -> Result<String> {
|
|
|
|
let command = command.stdout_capture().stderr_capture();
|
2021-07-20 15:07:55 +05:30
|
|
|
let output = command.run()?;
|
|
|
|
assert!(output.status.success());
|
|
|
|
let stdout = std::str::from_utf8(&output.stdout[..])
|
|
|
|
.unwrap()
|
|
|
|
.trim_end_matches(|c| c == '\n' || c == '\r')
|
|
|
|
.to_string();
|
2021-10-11 16:37:26 +05:30
|
|
|
|
2021-07-20 15:07:55 +05:30
|
|
|
Ok(stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the entire output. The command must return zero.
|
2021-10-11 16:37:26 +05:30
|
|
|
pub fn run_ok_raw(command: duct::Expression) -> Result<std::process::Output> {
|
|
|
|
let command = command.stdout_capture().stderr_capture();
|
2021-07-20 15:07:55 +05:30
|
|
|
let output = command.run()?;
|
|
|
|
assert!(output.status.success());
|
|
|
|
Ok(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns stderr, a non zero status must be returned
|
2021-10-11 16:37:26 +05:30
|
|
|
pub fn run_fail(command: duct::Expression) -> Result<String> {
|
|
|
|
let command = command.stdout_capture().stderr_capture();
|
2021-07-20 15:07:55 +05:30
|
|
|
let output = command.unchecked().run()?;
|
|
|
|
assert!(!output.status.success());
|
|
|
|
let stderr = std::str::from_utf8(&output.stderr[..]).unwrap().to_string();
|
|
|
|
Ok(stderr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the entire output, a non zero status must be returned
|
2021-10-11 16:37:26 +05:30
|
|
|
pub fn run_fail_raw(command: duct::Expression) -> Result<std::process::Output> {
|
|
|
|
let command = command.stdout_capture().stderr_capture();
|
2021-07-20 15:07:55 +05:30
|
|
|
let output = command.unchecked().run()?;
|
|
|
|
assert!(!output.status.success());
|
|
|
|
Ok(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|