From 010cbf244737456d4a10f568a5e037771012f9c5 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 21 Oct 2023 17:51:04 -0400 Subject: [PATCH] Implement write tool --- src/abstract_tree/tool.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/abstract_tree/tool.rs b/src/abstract_tree/tool.rs index b81c8ee..ef62e05 100644 --- a/src/abstract_tree/tool.rs +++ b/src/abstract_tree/tool.rs @@ -1,5 +1,5 @@ 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, path::{Path, PathBuf}, }; @@ -346,7 +346,16 @@ impl AbstractTree for Tool { 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::ToJson(_) => todo!(), Tool::ToString(_) => todo!(),