summaryrefslogtreecommitdiff
path: root/unix.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-08 06:43:33 -0600
committerJeff Carr <[email protected]>2024-11-08 06:43:33 -0600
commit55acea0bd769132db7bf420fef3b94fa21ca5f83 (patch)
treed43fb2b485cf0b1439a48037cf129a76e1d53ad0 /unix.go
parent29545d3f048ccb148429725d76d0894336985c2b (diff)
use go-cmd/cmdv0.22.12
Diffstat (limited to 'unix.go')
-rw-r--r--unix.go96
1 files changed, 12 insertions, 84 deletions
diff --git a/unix.go b/unix.go
index 19872a6..97f560e 100644
--- a/unix.go
+++ b/unix.go
@@ -1,7 +1,6 @@
package repostatus
import (
- "errors"
"fmt"
"io/ioutil"
"os"
@@ -12,6 +11,7 @@ import (
"strings"
"time"
+ "github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
@@ -117,88 +117,16 @@ func splitVersion(version string) (a, b, c string) {
}
}
-func (rs *RepoStatus) RunCmdEcho(parts []string) (error, string) {
- log.Info("RunCmdEcho()", parts)
- return rs.RunCmd(parts)
-}
-
-func (rs *RepoStatus) RunCmd(parts []string) (error, string) {
+func (rs *RepoStatus) Run(cmd []string) cmd.Status {
path := rs.realPath.String()
- err, _, output := shell.RunCmd(path, parts)
- if err != nil {
- log.Log(WARN, "cmd:", parts)
+ r := shell.PathRun(path, cmd)
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Log(WARN, "cmd:", cmd)
log.Log(WARN, "ouptput:", output)
- log.Log(WARN, "failed with error:", err)
+ log.Log(WARN, "failed with error:", r.Error)
}
- return err, output
-}
-
-// temp hack. fix this
-func runCmd(path string, parts []string) (error, bool, string) {
- return shell.RunCmd(path, parts)
-}
-
-func RunCmd(workingpath string, parts []string) (error, bool, string) {
- if len(parts) == 0 {
- log.Warn("command line was empty")
- return errors.New("empty"), false, ""
- }
- if parts[0] == "" {
- log.Warn("command line was empty")
- return errors.New("empty"), false, ""
- }
- thing := parts[0]
- parts = parts[1:]
- log.Log(INFO, "working path =", workingpath, "thing =", thing, "cmdline =", parts)
-
- // Create the command
- cmd := exec.Command(thing, parts...)
-
- // Set the working directory
- cmd.Dir = workingpath
-
- // Execute the command
- output, err := cmd.CombinedOutput()
- if err != nil {
- if thing == "git" {
- log.Log(INFO, "git ERROR. maybe okay", workingpath, "thing =", thing, "cmdline =", parts)
- log.Log(INFO, "git ERROR. maybe okay err =", err)
- if err.Error() == "exit status 1" {
- log.Log(INFO, "git ERROR. normal exit status 1")
- if parts[0] == "diff-index" {
- log.Log(INFO, "git normal diff-index when repo dirty")
- return nil, false, "git diff-index exit status 1"
- }
- }
- }
-
- log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
- log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
- log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
- log.Error(err)
- log.Warn("output was", string(output))
- log.Warn("cmd exited with error", err)
- // panic("fucknuts")
- return err, false, string(output)
-
- /* todo: see if there is a way to get the exit value
- // The command failed (non-zero exit status)
- if exitErr, ok := err.(*exec.ExitError); ok {
- // Assert that it is an exec.ExitError and get the exit code
- if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
- log.Warn("Exit Status: %d\n", status.ExitStatus())
- }
- } else {
- log.Warn("cmd.Run() failed with %s\n", err)
- }
- */
- }
-
- tmp := string(output)
- tmp = strings.TrimSpace(tmp)
-
- // Print the output
- return nil, true, tmp
+ return r
}
// Set the path to the package
@@ -438,10 +366,10 @@ func (rs *RepoStatus) XtermBash(args []string) {
func (rs *RepoStatus) DoAll(all [][]string) bool {
for _, cmd := range all {
log.Log(WARN, "doAll() RUNNING: cmd =", cmd)
- err, out := rs.RunCmd(cmd)
- if err != nil {
- log.Log(WARN, "doAll() err =", err)
- log.Log(WARN, "doAll() out =", out)
+ r := rs.Run(cmd)
+ if r.Error != nil {
+ log.Log(WARN, "doAll() err =", r.Error)
+ log.Log(WARN, "doAll() out =", r.Stdout)
return false
}
}