Merge pull request #11 from jonathandturner/fix_quotes

Fix quoted string handling
This commit is contained in:
Jonathan Turner 2019-05-18 07:45:28 -07:00 committed by GitHub
commit 362ca18f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 15 deletions

View File

@ -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<crate::parser::Item>,
input: VecDeque<Value>,
context: Arc<Mutex<Context>>,
) -> Result<VecDeque<Value>, ShellError> {
let command = &parsed[0].name()?;
let arg_list = parsed[1..].iter().map(|i| i.as_value()).collect();
let arg_list_strings: Vec<String> = 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())
}
}

View File

@ -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};

View File

@ -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 {
pub fn print(&self) -> String {
match self {
Item::Bare(s) => format!("{}", s),
Item::Quoted(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, " ")
}
}
}
impl Item {