Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Jul 17, 2020
1 parent d32db73 commit 8b1a021
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion execute-command-macro-impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "execute-command-macro-impl"
version = "0.1.3"
version = "0.1.4"
authors = ["Magic Len <[email protected]>"]
edition = "2018"
repository = "https://github.com/magiclen/execute"
Expand Down
15 changes: 3 additions & 12 deletions execute-command-macro-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ use syn::LitStr;

use execute_command_tokens::command_tokens;

/**
Generate the statements at compile time to create a `Command` instance by a command string.
```rust
#[macro_use] extern crate execute_command_macro_impl;
let command = command!("program arg1 arg2 -opt1 -opt2");
```
*/
#[proc_macro]
pub fn command(input: TokenStream) -> TokenStream {
let s = parse_macro_input!(input as LitStr).value();
Expand All @@ -39,14 +30,14 @@ pub fn command(input: TokenStream) -> TokenStream {
let command = match tokens_length {
0 => {
quote! {
std::process::Command::new("")
::std::process::Command::new("")
}
}
1 => {
let program = &tokens[0];

quote! {
std::process::Command::new(#program)
::std::process::Command::new(#program)
}
}
_ => {
Expand All @@ -55,7 +46,7 @@ pub fn command(input: TokenStream) -> TokenStream {

quote! {
{
let mut command = std::process::Command::new(#program);
let mut command = ::std::process::Command::new(#program);

command.args(&[#(#args,)*]);

Expand Down
2 changes: 1 addition & 1 deletion execute-command-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "execute-command-macro"
version = "0.1.3"
version = "0.1.4"
authors = ["Magic Len <[email protected]>"]
edition = "2018"
repository = "https://github.com/magiclen/execute"
Expand Down
4 changes: 2 additions & 2 deletions execute-command-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ let command = command_args!("program", "arg1", "arg2", "-opt1", "-opt2");
#[macro_export]
macro_rules! command_args {
($program:expr $(,)*) => {
std::process::Command::new($program)
::std::process::Command::new($program)
};
($program:expr, $arg:expr $(, $args:expr)* $(,)*) => {
{
let mut command = std::process::Command::new($program);
let mut command = ::std::process::Command::new($program);

command.arg(&$arg)$(.arg(&$args))*;

Expand Down

0 comments on commit 8b1a021

Please sign in to comment.