macro_rules! cmd {
    ($cmd:expr $(, $(@$cmdargs:expr,)* $cmdarg:expr)*; status, $($k:ident = $v:tt),*) => { ... };
    ($cmd:expr $(, $(@$cmdargs:expr,)* $cmdarg:expr)* $(; $($k:ident = $v:tt),*)?) => { ... };
}
Expand description

Run a command to completion.

This is a simple wrapper over the std::process::Command API. It expects at least one argument for the program to run. Every comma seperated argument thereafter is added to the command’s arguments. Arguments after an @-sign specify collections of arguments (specifically impl IntoIterator<Item = impl AsRef<OsStr>). The opional key=value arguments after a semicolon are simply translated to calling the std::process::Command::<key> method with value as its arguments.

Note: @-arguments must be followed by at least one normal argument. For example cmd!("cmd", @args) will not compile but cmd!("cmd", @args, "other") will. You can use key=value arguments to work around this limitation: cmd!("cmd"; args=(args)).

After building the command std::process::Command::status is called and its return value returned if the command was executed sucessfully otherwise an error is returned. If status is specified as the first key=value argument, the result of Command::status will be returned without checking if the command succeeded.

Examples

let args_list = ["--foo", "--bar", "value"];
cmd!("git", @args_list, "clone"; arg=("url.com"), env=("var", "value"));