summaryrefslogtreecommitdiff
path: root/run.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-03-09 16:50:49 -0600
committerJeff Carr <[email protected]>2024-03-09 16:50:49 -0600
commitf163738c86b84d8b6ddf12326d835de0191834bd (patch)
tree3165353c454c5dfae12fd3ff5ed71154ddec0100 /run.go
parent1ff1045445ecfb9b4a7f122d46436fcfcdd1b150 (diff)
return a structv0.22.1
Diffstat (limited to 'run.go')
-rw-r--r--run.go50
1 files changed, 37 insertions, 13 deletions
diff --git a/run.go b/run.go
index 7a4f3b6..ed43101 100644
--- a/run.go
+++ b/run.go
@@ -50,8 +50,8 @@ func Run(args []string) bool {
return false
}
- err = RunPath(dir, args)
- if err == nil {
+ r := RunPath(dir, args)
+ if r.ok {
return true
}
return false
@@ -59,13 +59,29 @@ func Run(args []string) bool {
var ErrorArgvEmpty error = errors.New("command was empty")
+type RunResult struct {
+ ok bool
+ argv []string
+ path string
+ output []byte
+ err error
+ outerr error
+}
+
// run, but set the working path
-func RunPath(path string, args []string) error {
+func RunPath(path string, args []string) *RunResult {
+ r := new(RunResult)
+ r.path = path
+ r.argv = args
if len(args) == 0 {
- return ErrorArgvEmpty
+ r.ok = true
+ r.err = ErrorArgvEmpty
+ return r
}
if args[0] == "" {
- return ErrorArgvEmpty
+ r.ok = false
+ r.err = ErrorArgvEmpty
+ return r
}
thing := args[0]
parts := args[1:]
@@ -76,17 +92,25 @@ func RunPath(path string, args []string) error {
log.Info("path =", path, "cmd =", strings.Join(args, " "))
if err := cmd.Run(); err != nil {
// Handle error if the command execution fails
- log.Info("RunPath() failed")
+ // log.Info("RunPath() failed")
// log.Info("cmd.Enviorn =", cmd.Environ())
out, outerr := cmd.Output()
- log.Info("cmd.output =", out)
- log.Info("cmd.output err=", outerr)
- log.Info("path =", path)
- log.Info("args =", args)
- log.Info("err =", err.Error())
- return err
+ // log.Info("cmd.output =", out)
+ // log.Info("cmd.output err=", outerr)
+ // log.Info("path =", path)
+ // log.Info("args =", args)
+ // log.Info("err =", err.Error())
+ r.ok = false
+ r.err = err
+ r.output = out
+ r.outerr = outerr
+ return r
}
- return nil
+ out, outerr := cmd.Output()
+ r.output = out
+ r.outerr = outerr
+ r.ok = true
+ return r
}
func (cmd *OldShell) Run(cmdline string) string {