execute_command_macro/
lib.rs

1/*!
2# Execute Command Macro
3
4Create `Command` instances using the `command!` macro or the `command_args!` macro.
5
6Also see [`execute`](https://crates.io/crates/execute).
7
8## Examples
9
10```rust
11#[macro_use] extern crate execute_command_macro;
12
13let command = command!("program arg1 arg2 'arg 3' -opt1 -opt2");
14```
15
16```rust
17#[macro_use] extern crate execute_command_macro;
18
19let command = command_args!("program", "arg1", "arg2", "-opt1", "-opt2");
20```
21*/
22
23/**
24Generate the statements at compile time to create a `Command` instance by a command string.
25
26```rust
27#[macro_use] extern crate execute_command_macro;
28
29let command = command!("program arg1 arg2 -opt1 -opt2");
30```
31*/
32pub use execute_command_macro_impl::command;
33
34/**
35Create a `Command` instance by inputting args separately.
36
37```rust
38#[macro_use] extern crate execute_command_macro;
39
40let command = command_args!("program", "arg1", "arg2", "-opt1", "-opt2");
41```
42*/
43#[macro_export]
44macro_rules! command_args {
45    ($program:expr $(,)*) => {
46        ::std::process::Command::new($program)
47    };
48    ($program:expr, $arg:expr $(, $args:expr)* $(,)*) => {
49        {
50            let mut command = ::std::process::Command::new($program);
51
52            command.arg(&$arg)$(.arg(&$args))*;
53
54            command
55        }
56    };
57}