From 8f17112a86e818849b1d145c28ffdf847aabc34a Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Fri, 26 Apr 2024 15:09:55 -0400 Subject: [PATCH] feat: add support for sub-tool option Signed-off-by: Donnie Adams --- exec.go | 4 ++++ exec_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/exec.go b/exec.go index 989b204..1863656 100644 --- a/exec.go +++ b/exec.go @@ -15,6 +15,7 @@ type Opts struct { CacheDir string `json:"cacheDir"` Quiet bool `json:"quiet"` Chdir string `json:"chdir"` + SubTool string `json:"subTool"` } func (o Opts) toArgs() []string { @@ -28,6 +29,9 @@ func (o Opts) toArgs() []string { if o.Chdir != "" { args = append(args, "--chdir="+o.Chdir) } + if o.SubTool != "" { + args = append(args, "--sub-tool="+o.SubTool) + } return append(args, "--quiet="+fmt.Sprint(o.Quiet)) } diff --git a/exec_test.go b/exec_test.go index 8b0ecca..008862b 100644 --- a/exec_test.go +++ b/exec_test.go @@ -135,6 +135,42 @@ func TestExecWithToolList(t *testing.T) { } } +func TestExecWithToolListAndSubTool(t *testing.T) { + shebang := "#!/bin/bash" + if runtime.GOOS == "windows" { + shebang = "#!/usr/bin/env powershell.exe" + } + tools := []fmt.Stringer{ + &Tool{ + Tools: []string{"echo"}, + Instructions: "echo hello there", + }, + &Tool{ + Name: "other", + Tools: []string{"echo"}, + Instructions: "echo hello somewhere else", + }, + &Tool{ + Name: "echo", + Tools: []string{"sys.exec"}, + Description: "Echoes the input", + Args: map[string]string{ + "input": "The string input to echo", + }, + Instructions: shebang + "\n echo ${input}", + }, + } + + out, err := ExecTool(context.Background(), Opts{SubTool: "other"}, tools...) + if err != nil { + t.Errorf("Error executing tool: %v", err) + } + + if !strings.Contains(out, "hello somewhere else") { + t.Errorf("Unexpected output: %s", out) + } +} + func TestStreamExec(t *testing.T) { tool := &FreeForm{Content: "What is the capital of the united states?"}