1
0

Implement workdir tool

This commit is contained in:
Jeff 2023-10-22 16:41:37 -04:00
parent b327068e17
commit bd83ccd301
5 changed files with 1241 additions and 1194 deletions

View File

@ -1,4 +1,5 @@
use std::{ use std::{
env::current_dir,
fs::{copy, metadata, read_dir, read_to_string, remove_file, write, File}, fs::{copy, metadata, read_dir, read_to_string, remove_file, write, File},
io::Write, io::Write,
path::PathBuf, path::PathBuf,
@ -21,6 +22,7 @@ pub enum Tool {
Output(Vec<Expression>), Output(Vec<Expression>),
OutputError(Vec<Expression>), OutputError(Vec<Expression>),
Type(Expression), Type(Expression),
Workdir,
// Filesystem // Filesystem
Append(Vec<Expression>), Append(Vec<Expression>),
@ -117,6 +119,7 @@ impl AbstractTree for Tool {
Tool::Type(expression) Tool::Type(expression)
} }
"workdir" => Tool::Workdir,
"append" => { "append" => {
let expressions = parse_expressions(source, node)?; let expressions = parse_expressions(source, node)?;
@ -314,6 +317,11 @@ impl AbstractTree for Tool {
Ok(Value::String(value_type.to_string())) Ok(Value::String(value_type.to_string()))
} }
Tool::Workdir => {
let workdir = current_dir()?.to_string_lossy().to_string();
Ok(Value::String(workdir))
}
Tool::Append(expressions) => { Tool::Append(expressions) => {
let path_value = expressions[0].run(source, context)?; let path_value = expressions[0].run(source, context)?;
let path = path_value.as_string()?; let path = path_value.as_string()?;

View File

@ -267,6 +267,7 @@ module.exports = grammar({
'output', 'output',
'output_error', 'output_error',
'type', 'type',
'workdir',
// Filesystem // Filesystem
'append', 'append',

View File

@ -1094,6 +1094,10 @@
"type": "STRING", "type": "STRING",
"value": "type" "value": "type"
}, },
{
"type": "STRING",
"value": "workdir"
},
{ {
"type": "STRING", "type": "STRING",
"value": "append" "value": "append"
@ -1168,11 +1172,11 @@
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "rows" "value": "columns"
}, },
{ {
"type": "STRING", "type": "STRING",
"value": "columns" "value": "rows"
} }
] ]
} }

View File

@ -897,6 +897,10 @@
"type": "while", "type": "while",
"named": false "named": false
}, },
{
"type": "workdir",
"named": false
},
{ {
"type": "write", "type": "write",
"named": false "named": false

File diff suppressed because it is too large Load Diff