From 7df78a286464fe88dcd53e7a9d2f079ed596eaf3 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 1 Sep 2015 15:31:12 +0200 Subject: [PATCH] Added run helper function --- make.go | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/make.go b/make.go index 746f938d1..ad5a9acca 100644 --- a/make.go +++ b/make.go @@ -276,19 +276,44 @@ func clean() error { return nil } -// trace is a helper fucntion that writes a command +// run is a helper function that executes commands +// and assigns stdout and stderr targets +func run(command string, args ...string) error { + cmd := exec.Command(command, args...) + + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + trace(cmd.Args) + err := cmd.Run() + + if err != nil { + return err + } + + return nil +} + +// helper function to parse the git revision +func rev() string { + cmd := exec.Command( + "git", + "rev-parse", + "--short", + "HEAD") + + raw, err := cmd.CombinedOutput() + + if err != nil { + return "HEAD" + } + + return strings.Trim(string(raw), "\n") +} + +// trace is a helper function that writes a command // to stdout similar to bash +x func trace(args []string) { print("+ ") println(strings.Join(args, " ")) } - -// helper function to parse the git revision -func rev() string { - cmd := exec.Command("git", "rev-parse", "--short", "HEAD") - raw, err := cmd.CombinedOutput() - if err != nil { - return "HEAD" - } - return strings.Trim(string(raw), "\n") -}