1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
package main
import (
"errors"
"os/exec"
"strings"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
var repopath string = "/home/jcarr/"
// if dryRun == true, then it just prints out the values
// but doesn't do anything
func goMake(dryRun string) bool {
var workingPath string = "go/src"
for _, line := range me.script {
if len(line) == 0 {
continue
}
if line[0] == "cd" {
switch len(line) {
case 1:
log.Verbose("do cmdPwd() to go root", repopath+"go/src")
workingPath = ""
case 2:
log.Verbose("do cmdPwd() here", line)
workingPath = line[1]
default:
log.Warn("bad cd", line)
return false
}
continue
}
cmd := line[0]
s := strings.Join(line[1:], " ")
path := repopath + workingPath
log.Warn("NEED TO RUN path =", path, "cmd =", cmd, s)
if dryRun == "--dry-run" {
continue
}
if dryRun == "--doit" {
log.Warn("Actually RUN path =", path, "cmd =", cmd, s)
err, b, output := repostatus.RunCmd(path, line)
if err != nil {
log.Info("ABEND EXECUTION")
log.Info("error =", err)
log.Info("b =", b)
log.Info("output =", output)
return false
}
// log.Warn("output was =", output)
continue
}
log.Warn("don't know what to do. dryRun ==", dryRun)
return false
}
return true
}
func setGitCommands() {
var tmp []string
// convert to displayable to the user text
for _, line := range me.script {
s := strings.Join(line, " ")
log.Warn("s =", s)
tmp = append(tmp, s)
}
cmds.Set(strings.Join(tmp, "\n"))
}
/*
func runCommandsOld() bool {
for _, line := range me.script {
s := strings.Join(line, " ")
log.Warn("NEED TO RUN:", s)
err, b, output := repostatus.RunCmd(repopath, line)
if err != nil {
log.Warn("ABEND EXECUTION")
log.Warn("error =", err)
log.Warn("output =", output)
return false
}
log.Warn("Returned with b =", b)
log.Warn("output was =", output)
log.Warn("RUN DONE")
}
return true
}
*/
func RunCmdNew(workingpath string, parts []string) (error, bool, string) {
log.Warn("RUN NEW:", workingpath, parts)
return RunCmd(workingpath, parts)
}
func RunCmd(workingpath string, parts []string) (error, bool, string) {
log.Warn("RUN CMD:", workingpath, parts)
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.Warn("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 {
log.Error(err)
log.Warn("output was", string(output))
log.Warn("cmd exited with error", err)
return err, false, string(output)
}
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output
return nil, true, tmp
}
|