macro_rules! cmd_build {
($builder:ident $(, $(@$cmdargs:expr,)* $cmdarg:expr)* $(; $($k:ident = $v:tt),*)?) => { ... };
}
Expand description
Build a command using a given std::process::Command
or Cmd
and return it.
The first argument is expected to be a std::process::Command
or Cmd
instance.
For a new
builder the second argument, the program to run (passed to
std::process::Command::new
) is mandatory. 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_build!(new, "cmd", @args)
will not compile but cmd_build!(new, "cmd", @args, "other")
will. You can use key=value
arguments to work around this limitation:
cmd_build!(new, "cmd"; args=(args))
.
At the end the built std::process::Command
is returned.
Examples
let args_list = ["--foo", "--bar", "value"];
let mut cmd = Cmd::new("git");
let mut cmd = cmd_build!(cmd, @args_list, "clone"; arg=("url.com"), env=("var", "value"));