From 50a8debecc13686ba29356b28d30c33555e662f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolai=20Str=C3=A4ssle?= Date: Wed, 23 Jun 2021 13:36:25 +0200 Subject: [PATCH] allow multiple commands to run on build --- daemon.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/daemon.go b/daemon.go index f83f7ac..6e1d9a1 100644 --- a/daemon.go +++ b/daemon.go @@ -151,29 +151,37 @@ func failColor(format string, args ...interface{}) string { func build() bool { log.Println(okColor("Running build command!")) - args := strings.Split(*flagBuild, " ") - if len(args) == 0 { - // If the user has specified and empty then we are done. - return true - } + commands := strings.Split(*flagBuild, "&&") + success := true + for _, c := range commands { + c = strings.TrimSpace(c) + args := strings.Split(c, " ") + if len(args) == 0 { + // If the user has specified and empty then we are done. + return true + } - cmd := exec.Command(args[0], args[1:]...) + cmd := exec.Command(args[0], args[1:]...) - if *flagBuildDir != "" { - cmd.Dir = *flagBuildDir - } else if len(flagDirectories) > 0 { - cmd.Dir = flagDirectories[0] - } + if *flagBuildDir != "" { + cmd.Dir = *flagBuildDir + } else if len(flagDirectories) > 0 { + cmd.Dir = flagDirectories[0] + } - output, err := cmd.CombinedOutput() + output, err := cmd.CombinedOutput() - if err == nil { - log.Println(okColor("Build ok.")) - } else { - log.Println(failColor("Error while building:\n"), failColor(string(output))) + if err == nil { + log.Println(okColor("Build ok.")) + } else { + log.Println(failColor("Error while building:\n"), failColor(string(output))) + if success { + success = false + } + } } - return err == nil + return success } func matchesPattern(pattern *regexp.Regexp, file string) bool {