1
0

Implement write tool

This commit is contained in:
Jeff 2023-10-21 17:51:04 -04:00
parent 3355310d9d
commit 010cbf2447

View File

@ -1,5 +1,5 @@
use std::{ use std::{
fs::{copy, metadata, read_dir, read_to_string, remove_file, File}, fs::{copy, metadata, read_dir, read_to_string, remove_file, write, File},
io::Write, io::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@ -346,7 +346,16 @@ impl AbstractTree for Tool {
Ok(Value::Empty) Ok(Value::Empty)
} }
Tool::Write(_) => todo!(), Tool::Write(expressions) => {
let path_value = expressions[0].run(source, context)?;
let path = path_value.as_string()?;
let data_value = expressions[1].run(source, context)?;
let data = data_value.as_string()?;
write(path, data)?;
Ok(Value::Empty)
}
Tool::FromJson(_) => todo!(), Tool::FromJson(_) => todo!(),
Tool::ToJson(_) => todo!(), Tool::ToJson(_) => todo!(),
Tool::ToString(_) => todo!(), Tool::ToString(_) => todo!(),