shell exec for 'forge commit'

This commit is contained in:
Jeff Carr 2025-01-12 06:35:36 -06:00
parent d5f45aef13
commit 9f2ef46cd9
1 changed files with 48 additions and 0 deletions

48
exec.go Normal file
View File

@ -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
}