Added run helper function

This commit is contained in:
Thomas Boerger 2015-09-01 15:31:12 +02:00
parent 209d71c1f6
commit 7df78a2864

47
make.go
View file

@ -276,19 +276,44 @@ func clean() error {
return nil 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 // to stdout similar to bash +x
func trace(args []string) { func trace(args []string) {
print("+ ") print("+ ")
println(strings.Join(args, " ")) 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")
}