macro_rules! cmd {
($sh:expr, $cmd:literal) => { ... };
}
Expand description
Constructs a Cmd
from the given string.
ยงExamples
Basic:
let sh = Shell::new()?;
cmd!(sh, "echo hello world").run()?;
Interpolation:
let greeting = "hello world";
let c = cmd!(sh, "echo {greeting}");
assert_eq!(c.to_string(), r#"echo "hello world""#);
let c = cmd!(sh, "echo '{greeting}'");
assert_eq!(c.to_string(), r#"echo {greeting}"#);
let c = cmd!(sh, "echo {greeting}!");
assert_eq!(c.to_string(), r#"echo "hello world!""#);
let c = cmd!(sh, "echo 'spaces '{greeting}' around'");
assert_eq!(c.to_string(), r#"echo "spaces hello world around""#);
Splat interpolation:
let args = ["hello", "world"];
let c = cmd!(sh, "echo {args...}");
assert_eq!(c.to_string(), r#"echo hello world"#);
let arg1: Option<&str> = Some("hello");
let arg2: Option<&str> = None;
let c = cmd!(sh, "echo {arg1...} {arg2...}");
assert_eq!(c.to_string(), r#"echo hello"#);