diff --git a/src/cli.rs b/src/cli.rs index 19089858e6..24f9e61976 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -309,7 +309,8 @@ fn classify_command( })) } false => { - let arg_list_strings: Vec = args.iter().map(|i| i.print()).collect(); + let arg_list_strings: Vec = + args.iter().map(|i| i.as_external_arg()).collect(); Ok(ClassifiedCommand::External(ExternalCommand { name: other.to_string(), diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 8ccfdf7bf8..b00b2f31f3 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -64,6 +64,17 @@ impl Expression { } } + crate fn as_external_arg(&self) -> String { + match self { + Expression::Leaf(l) => l.as_external_arg(), + Expression::Parenthesized(p) => p.as_external_arg(), + Expression::Block(b) => b.as_external_arg(), + Expression::VariableReference(r) => r.as_external_arg(), + Expression::Path(p) => p.as_external_arg(), + Expression::Binary(b) => b.as_external_arg(), + } + } + crate fn as_string(&self) -> Option { match self { Expression::Leaf(Leaf::String(s)) => Some(s.to_string()), @@ -82,6 +93,10 @@ impl Block { fn print(&self) -> String { format!("{{ {} }}", self.expr.print()) } + + fn as_external_arg(&self) -> String { + format!("{{ {} }}", self.expr.as_external_arg()) + } } #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)] @@ -93,6 +108,10 @@ impl Parenthesized { fn print(&self) -> String { format!("({})", self.expr.print()) } + + fn as_external_arg(&self) -> String { + format!("({})", self.expr.as_external_arg()) + } } #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Getters, new)] @@ -114,6 +133,16 @@ impl Path { out } + + crate fn as_external_arg(&self) -> String { + let mut out = self.head.as_external_arg(); + + for item in self.tail.iter() { + out.push_str(&format!(".{}", item)); + } + + out + } } #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] @@ -133,6 +162,10 @@ impl Variable { Variable::Other(s) => format!("${}", s), } } + + fn as_external_arg(&self) -> String { + self.print() + } } impl FromStr for Variable { @@ -191,6 +224,15 @@ impl Leaf { Leaf::Int(i) => format!("{}", i), } } + + fn as_external_arg(&self) -> String { + match self { + Leaf::String(s) => format!("{}", s), + Leaf::Bare(path) => format!("{}", path.to_string()), + Leaf::Boolean(b) => format!("{}", b), + Leaf::Int(i) => format!("{}", i), + } + } } #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)] @@ -209,6 +251,15 @@ impl Binary { self.right.print() ) } + + fn as_external_arg(&self) -> String { + format!( + "{} {} {}", + self.left.as_external_arg(), + self.operator.print(), + self.right.as_external_arg() + ) + } } #[derive(Debug, Clone)]