From 196667d260a769e4cc5b878ae7c07eacc06d8e55 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 1 Jun 2019 13:32:33 +1200 Subject: [PATCH] Add support for internal->external --- src/commands/classified.rs | 49 ++++++++++++++++++++++++++++++-------- src/parser/ast.rs | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/commands/classified.rs b/src/commands/classified.rs index 0418fcf2f6..acafc9c161 100644 --- a/src/commands/classified.rs +++ b/src/commands/classified.rs @@ -105,10 +105,6 @@ impl InternalCommand { Ok(stream.boxed() as InputStream) } - - crate fn name(&self) -> &str { - self.command.name() - } } crate struct ExternalCommand { @@ -129,10 +125,47 @@ impl ExternalCommand { input: ClassifiedInputStream, stream_next: StreamNext, ) -> Result { - let mut process = Exec::shell(&self.name); + let mut process; + #[cfg(windows)] + { + process = Exec::cmd("cmd.exe"); + } + #[cfg(not(windows))] + { + process = Exec::cmd("sh"); + } + let inputs: Vec = input.objects.collect().await; + let mut arg_string = format!("{}", self.name); for arg in self.args { - process = process.arg(arg) + arg_string.push_str(" "); + arg_string.push_str(&arg); + } + + if arg_string.contains("$it") { + let mut new_arg_string = String::new(); + + let tmp = arg_string.clone(); + let mut first = true; + for i in &inputs { + if !first { + new_arg_string.push_str(" && "); + } else { + first = false; + } + new_arg_string.push_str(&tmp.replace("$it", &i.as_string().unwrap())); + } + + arg_string = new_arg_string; + } + + #[cfg(windows)] + { + process = process.args(&["/c", &arg_string]); + } + #[cfg(not(windows))] + { + process = process.args(&["-c", &arg_string]); } process = process.cwd(context.env.lock().unwrap().cwd()); @@ -168,8 +201,4 @@ impl ExternalCommand { } } } - - crate fn name(&self) -> &str { - &self.name[..] - } } diff --git a/src/parser/ast.rs b/src/parser/ast.rs index a17a4536f0..d8a91994d6 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -230,7 +230,7 @@ impl Leaf { fn as_external_arg(&self) -> String { match self { - Leaf::String(s) => format!("{}", s), + Leaf::String(s) => format!("\"{}\"", s), Leaf::Bare(path) => format!("{}", path.to_string()), Leaf::Boolean(b) => format!("{}", b), Leaf::Int(i) => format!("{}", i),