From 487b3f29a2f5c7660f2cd9b6c047914d0f8c9742 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 17 Oct 2023 12:58:25 -0400 Subject: [PATCH] Implement sh, bash, fish and zsh tools --- src/abstract_tree/tool.rs | 73 +++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/src/abstract_tree/tool.rs b/src/abstract_tree/tool.rs index 8f6d91e..bf62449 100644 --- a/src/abstract_tree/tool.rs +++ b/src/abstract_tree/tool.rs @@ -1,4 +1,4 @@ -use std::fs::read_to_string; +use std::{fs::read_to_string, process::Command}; use rand::{random, thread_rng, Rng}; use serde::{Deserialize, Serialize}; @@ -221,11 +221,72 @@ impl Tool { Value::Table(help_table) } - Tool::Raw => todo!(), - Tool::Sh => todo!(), - Tool::Bash => todo!(), - Tool::Fish => todo!(), - Tool::Zsh => todo!(), + Tool::Raw => { + let program = values[0].as_string()?; + let mut command = Command::new(program); + + for value in &values[1..] { + let arg = value.as_string()?; + + command.arg(arg); + } + + command.spawn()?.wait()?; + + Value::Empty + } + Tool::Sh => { + let mut command = Command::new("sh"); + + for value in values { + let arg = value.as_string()?; + + command.arg(arg); + } + + command.spawn()?.wait()?; + + Value::Empty + } + Tool::Bash => { + let mut command = Command::new("bash"); + + for value in values { + let arg = value.as_string()?; + + command.arg(arg); + } + + command.spawn()?.wait()?; + + Value::Empty + } + Tool::Fish => { + let mut command = Command::new("fish"); + + for value in values { + let arg = value.as_string()?; + + command.arg(arg); + } + + command.spawn()?.wait()?; + + Value::Empty + } + Tool::Zsh => { + let mut command = Command::new("zsh"); + + for value in values { + let arg = value.as_string()?; + + command.arg(arg); + } + + command.spawn()?.wait()?; + + Value::Empty + } Tool::FromCsv => todo!(), Tool::ToCsv => todo!(), Tool::FromJson => {