cmd!() { /* proc-macro */ }Expand description
Helper to construct a Command with arguments.
The macro uses the syntax:
cmd: arg1, arg2That is, the command path, optionally followed by a colon (:) followed by one or
more comma delimited arguments.
Note that cmd! defers to cargs! to parse the arguments.
The macro is powerful enough to support raw path identifiers:
let c = cmd!(ls); // no args
assert_eq!(&c.cmd_str(), "ls");
let c = cmd!(ls: foo/bar, zog);
assert_eq!(&c.cmd_str(), "ls foo/bar zog");
let c = cmd!(./local-script.sh: foo/bar, zog);
assert_eq!(&c.cmd_str(), "./local-script.sh foo/bar zog");Literals are supported:
let c = cmd!(ls: "foo bar", 1.23);
assert_eq!(&c.cmd_str(), r#"ls "foo bar" 1.23"#);Arguments wrapped in braces ({ ... }) are treated as expressions to be evaluated.
This effectively writes { ... }.to_string().
let h = "hello";
let c = cmd!(ls: {h}, {format!("world")});
assert_eq!(&c.cmd_str(), "ls hello world");