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