From c55bfe1ac49ae519c310d8a3fdd1a4e44c0f021b Mon Sep 17 00:00:00 2001 From: rinocs Date: Fri, 12 Dec 2025 15:22:05 +0100 Subject: [PATCH] feat: add ExecCommand method for executing shell commands --- plugins/util.go | 44 +++++++++++- plugins/util_test.go | 75 +++++++++++++++++++++ src_docs/content/doc/filters/js/packages.md | 23 +++++++ 3 files changed, 141 insertions(+), 1 deletion(-) diff --git a/plugins/util.go b/plugins/util.go index 1f395a1..1612c2e 100644 --- a/plugins/util.go +++ b/plugins/util.go @@ -1,9 +1,13 @@ package plugins import ( - "github.com/Matrix86/driplane/utils" + "errors" "os" + "os/exec" + "strings" "time" + + "github.com/Matrix86/driplane/utils" ) // UtilPackage contains useful generic methods @@ -106,3 +110,41 @@ func (c *UtilPackage) Sha512File(filename string) UtilResponse { Value: hash, } } + +// Ecexute shell command +func (c *UtilPackage) ExecCommand(commandParts []string, inputData string) UtilResponse { + if len(commandParts) == 0 { + return UtilResponse{ + Error: errors.New("no command provided"), + Status: false, + Value: "", + } + } + + executable := commandParts[0] + args := commandParts[1:] + + cmd := exec.Command(executable, args...) + + // If inputData is provided, write it to the command's Stdin + // This replaces '< - `commandParts[0]` is the | +| | executable.
- `commandParts[1:]` are the arguments.
- inputData` is written to the| +| | Standard Input (stdin) of the command. | \ No newline at end of file