2014-12-09 03:16:07 +00:00
|
|
|
package main
|
|
|
|
|
2014-12-09 07:54:35 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2014-12-10 16:12:46 +00:00
|
|
|
"github.com/dballard/warren/src/warren"
|
2014-12-09 07:54:35 +00:00
|
|
|
"log"
|
2014-12-09 16:07:27 +00:00
|
|
|
"os"
|
2014-12-09 07:54:35 +00:00
|
|
|
"os/exec"
|
2014-12-10 06:43:10 +00:00
|
|
|
"time"
|
2014-12-09 07:54:35 +00:00
|
|
|
)
|
2014-12-09 03:16:07 +00:00
|
|
|
|
2014-12-10 06:43:10 +00:00
|
|
|
var buildUsage = `
|
|
|
|
warren build - Runs go build and populates the following variables:
|
|
|
|
|
2014-12-10 06:51:45 +00:00
|
|
|
Build.GitBranch from git
|
|
|
|
Build.GitHash from git
|
|
|
|
Build.Date from system time
|
2014-12-10 06:43:10 +00:00
|
|
|
`
|
|
|
|
|
2014-12-09 03:16:07 +00:00
|
|
|
var buildCmd = &Command{
|
|
|
|
Name: "build",
|
|
|
|
Usage: "",
|
|
|
|
Summary: "build the go server in the current directory",
|
2014-12-10 06:43:10 +00:00
|
|
|
Help: buildUsage,
|
2014-12-09 03:16:07 +00:00
|
|
|
Run: buildRun,
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildRun(cmd *Command, args ...string) {
|
2014-12-10 06:43:10 +00:00
|
|
|
if len(args) > 0 && args[0] == "help" {
|
|
|
|
fmt.Print(cmd.Help)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
date := time.Now().Format(time.RFC3339)
|
2014-12-10 16:12:46 +00:00
|
|
|
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.Build.Date %s -X main.Build.GitHash %s -X main.Build.GitBranch %s\"", date, warren.GitHash(), warren.GitBranch()))
|
2014-12-10 06:43:10 +00:00
|
|
|
gobuild.Stderr = os.Stderr
|
|
|
|
gobuild.Stdout = os.Stdout
|
2014-12-10 16:12:46 +00:00
|
|
|
err := gobuild.Run()
|
2014-12-09 07:54:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-12-09 03:16:07 +00:00
|
|
|
}
|