Skip to content

Commit 50a8deb

Browse files
author
Nikolai Strässle
committed
allow multiple commands to run on build
1 parent 39b144a commit 50a8deb

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

daemon.go

+25-17
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,37 @@ func failColor(format string, args ...interface{}) string {
151151
func build() bool {
152152
log.Println(okColor("Running build command!"))
153153

154-
args := strings.Split(*flagBuild, " ")
155-
if len(args) == 0 {
156-
// If the user has specified and empty then we are done.
157-
return true
158-
}
154+
commands := strings.Split(*flagBuild, "&&")
155+
success := true
156+
for _, c := range commands {
157+
c = strings.TrimSpace(c)
158+
args := strings.Split(c, " ")
159+
if len(args) == 0 {
160+
// If the user has specified and empty then we are done.
161+
return true
162+
}
159163

160-
cmd := exec.Command(args[0], args[1:]...)
164+
cmd := exec.Command(args[0], args[1:]...)
161165

162-
if *flagBuildDir != "" {
163-
cmd.Dir = *flagBuildDir
164-
} else if len(flagDirectories) > 0 {
165-
cmd.Dir = flagDirectories[0]
166-
}
166+
if *flagBuildDir != "" {
167+
cmd.Dir = *flagBuildDir
168+
} else if len(flagDirectories) > 0 {
169+
cmd.Dir = flagDirectories[0]
170+
}
167171

168-
output, err := cmd.CombinedOutput()
172+
output, err := cmd.CombinedOutput()
169173

170-
if err == nil {
171-
log.Println(okColor("Build ok."))
172-
} else {
173-
log.Println(failColor("Error while building:\n"), failColor(string(output)))
174+
if err == nil {
175+
log.Println(okColor("Build ok."))
176+
} else {
177+
log.Println(failColor("Error while building:\n"), failColor(string(output)))
178+
if success {
179+
success = false
180+
}
181+
}
174182
}
175183

176-
return err == nil
184+
return success
177185
}
178186

179187
func matchesPattern(pattern *regexp.Regexp, file string) bool {

0 commit comments

Comments
 (0)