Skip to content

Commit 1a99d2a

Browse files
committed
fix: add ability to set required extensions for certain commands
Some commands, like powershell, require the files it runs to end with a particular extension. This change sets up this requirement with the ability to add more later. Signed-off-by: Donnie Adams <[email protected]>
1 parent 51ad1ad commit 1a99d2a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/engine/cmd.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import (
2020
"github.com/gptscript-ai/gptscript/pkg/version"
2121
)
2222

23+
var requiredFileExtensions = map[string]string{
24+
"powershell.exe": "*.ps1",
25+
"powershell": "*.ps1",
26+
}
27+
2328
func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCategory ToolCategory) (cmdOut string, cmdErr error) {
2429
id := counter.Next()
2530

@@ -198,7 +203,12 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
198203
)
199204

200205
if strings.TrimSpace(rest) != "" {
201-
f, err := os.CreateTemp("", version.ProgramName)
206+
pattern := version.ProgramName
207+
if ext := requiredFileExtensions[args[0]]; ext != "" {
208+
pattern += ext
209+
}
210+
211+
f, err := os.CreateTemp("", pattern)
202212
if err != nil {
203213
return nil, nil, err
204214
}

0 commit comments

Comments
 (0)