From 75b7842618a6e5bff0ec6705dfd77e624e64041c Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 18 May 2019 07:42:55 -0700 Subject: [PATCH] Fix quoted string handling --- src/main.rs | 9 ++++++--- src/parser.rs | 2 +- src/parser/parse.rs | 20 +++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4d97f4da23..8170d63516 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,7 +145,6 @@ fn process_line( for item in parsed { input = match process_command( - crate::parser::print_items(&item), item.clone(), input, context.clone(), @@ -181,13 +180,13 @@ fn process_line( } fn process_command( - line: String, parsed: Vec, input: VecDeque, context: Arc>, ) -> Result, ShellError> { let command = &parsed[0].name()?; let arg_list = parsed[1..].iter().map(|i| i.as_value()).collect(); + let arg_list_strings: Vec = parsed[1..].iter().map(|i| i.print()).collect(); if command == &"format" { format(input, context); @@ -225,7 +224,11 @@ fn process_command( } false => { - Exec::shell(line).cwd(ctx.env.cwd()).join().unwrap(); + Exec::shell(command) + .args(&arg_list_strings) + .cwd(ctx.env.cwd()) + .join() + .unwrap(); Ok(VecDeque::new()) } } diff --git a/src/parser.rs b/src/parser.rs index 76adf67e6c..909d77fdd8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,4 +1,4 @@ crate mod completer; crate mod parse; -crate use self::parse::{print_items, shell_parser, Item}; +crate use self::parse::{shell_parser, Item}; diff --git a/src/parser/parse.rs b/src/parser/parse.rs index fc001263e0..6ad5807a0d 100644 --- a/src/parser/parse.rs +++ b/src/parser/parse.rs @@ -65,18 +65,16 @@ impl Item { Item::Operator(o) => Value::Primitive(Primitive::Operator(o.clone())), } } -} -crate fn print_items(items: &[Item]) -> String { - let formatted = items.iter().map(|item| match item { - Item::Bare(s) => format!("{}", s), - Item::Quoted(s) => format!("{:?}", s), - Item::Int(i) => format!("{:?}", i), - Item::Boolean(b) => format!("{:?}", b), - Item::Operator(o) => o.print(), - }); - - itertools::join(formatted, " ") + pub fn print(&self) -> String { + match self { + Item::Bare(s) => format!("{}", s), + Item::Quoted(s) => format!("{}", s), + Item::Int(i) => format!("{:?}", i), + Item::Boolean(b) => format!("{:?}", b), + Item::Operator(o) => o.print(), + } + } } impl Item {