Implement tools
This commit is contained in:
parent
6f3e62e555
commit
7e2d280921
@ -17,11 +17,11 @@ pub enum Tool {
|
|||||||
|
|
||||||
// Filesystem
|
// Filesystem
|
||||||
Append(Vec<Expression>),
|
Append(Vec<Expression>),
|
||||||
Metadata(Vec<Expression>),
|
Metadata(Expression),
|
||||||
Move(Option<Expression>),
|
Move(Vec<Expression>),
|
||||||
Read(Expression),
|
Read(Expression),
|
||||||
Remove(Vec<Expression>),
|
Remove(Expression),
|
||||||
Trash(Vec<Expression>),
|
Trash(Expression),
|
||||||
Write(Vec<Expression>),
|
Write(Vec<Expression>),
|
||||||
|
|
||||||
// Format conversion
|
// Format conversion
|
||||||
@ -103,74 +103,90 @@ impl AbstractTree for Tool {
|
|||||||
Tool::Append(expressions)
|
Tool::Append(expressions)
|
||||||
}
|
}
|
||||||
"metadata" => {
|
"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" => {
|
"move" => {
|
||||||
let expressions = parse_expressions(source, node)?;
|
let expressions = parse_expressions(source, node)?;
|
||||||
|
|
||||||
Tool::OutputError(expressions)
|
Error::expect_tool_argument_amount("move", 2, expressions.len())?;
|
||||||
|
|
||||||
|
Tool::Move(expressions)
|
||||||
}
|
}
|
||||||
"read" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"write" => {
|
||||||
let expressions = parse_expressions(source, node)?;
|
let expressions = parse_expressions(source, node)?;
|
||||||
|
|
||||||
Tool::OutputError(expressions)
|
Error::expect_tool_argument_amount("write", 2, expressions.len())?;
|
||||||
|
|
||||||
|
Tool::Write(expressions)
|
||||||
}
|
}
|
||||||
"from_json" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"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" => {
|
"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 {
|
return Err(Error::UnexpectedSyntaxNode {
|
||||||
|
Loading…
Reference in New Issue
Block a user