diff --git a/src/abstract_tree/tool.rs b/src/abstract_tree/tool.rs index f169077..5f5073e 100644 --- a/src/abstract_tree/tool.rs +++ b/src/abstract_tree/tool.rs @@ -17,11 +17,11 @@ pub enum Tool { // Filesystem Append(Vec), - Metadata(Vec), - Move(Option), + Metadata(Expression), + Move(Vec), Read(Expression), - Remove(Vec), - Trash(Vec), + Remove(Expression), + Trash(Expression), Write(Vec), // Format conversion @@ -103,74 +103,90 @@ impl AbstractTree for Tool { Tool::Append(expressions) } "metadata" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Metadata(expression) } "move" => { let expressions = parse_expressions(source, node)?; - Tool::OutputError(expressions) + Error::expect_tool_argument_amount("move", 2, expressions.len())?; + + Tool::Move(expressions) } "read" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Read(expression) } "remove" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Remove(expression) } "trash" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Trash(expression) } "write" => { let expressions = parse_expressions(source, node)?; - Tool::OutputError(expressions) + Error::expect_tool_argument_amount("write", 2, expressions.len())?; + + Tool::Write(expressions) } "from_json" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::FromJson(expression) } "to_json" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::ToJson(expression) } "to_string" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::ToString(expression) } "bash" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Bash(expression) } "fish" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Fish(expression) } "raw" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Raw(expression) } "sh" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Sh(expression) } "zsh" => { - let expressions = parse_expressions(source, node)?; + let expression_node = node.child(2).unwrap(); + let expression = Expression::from_syntax_node(source, expression_node)?; - Tool::OutputError(expressions) + Tool::Zsh(expression) } _ => { return Err(Error::UnexpectedSyntaxNode {