From 1534b9fbbcd883b5820d53c86e4923185574cfe0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Jan 2025 06:35:36 -0600 Subject: [PATCH] shell exec for 'forge commit' --- exec.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 exec.go diff --git a/exec.go b/exec.go new file mode 100644 index 0000000..57b8605 --- /dev/null +++ b/exec.go @@ -0,0 +1,48 @@ +package shell + +import ( + "errors" + "os" + "os/exec" + + "go.wit.com/log" +) + +func Exec(args []string) error { + if len(args) == 0 { + return errors.New("Error: Command slice is empty.") + } + + // Start a long-running process, capture stdout and stderr + a, b := RemoveFirstElement(args) + + process := exec.Command(a, b...) + process.Stderr = os.Stderr + process.Stdin = os.Stdin + process.Stdout = os.Stdout + process.Start() + err := process.Wait() + log.Log(INFO, "shell.Exec() err =", err) + return nil +} + +func ExecCheck(args []string) error { + if len(args) == 0 { + return errors.New("Error: Command slice is empty.") + } + + // Start a long-running process, capture stdout and stderr + a, b := RemoveFirstElement(args) + + process := exec.Command(a, b...) + process.Stderr = os.Stderr + process.Stdin = os.Stdin + process.Stdout = os.Stdout + err := process.Run() + if err != nil { + log.Info("ExecCheck() err", err) + return err + } + log.Info("ExecCheck() nil") + return nil +}