warren/cmd/warren/cmd_build.go

43 lines
916 B
Go
Raw Normal View History

package main
2014-12-09 08:54:35 +01:00
import (
"fmt"
2014-12-13 08:54:02 +01:00
"github.com/dballard/warren/lib/warren"
2014-12-09 08:54:35 +01:00
"log"
2014-12-09 17:07:27 +01:00
"os"
2014-12-09 08:54:35 +01:00
"os/exec"
2014-12-10 07:43:10 +01:00
"time"
2014-12-09 08:54:35 +01:00
)
2014-12-10 07:43:10 +01:00
var buildUsage = `
warren build - Runs go build and populates the following variables:
2014-12-12 06:47:29 +01:00
BuildGitBranch from git
BuildGitHash from git
BuildDate from system time
2014-12-10 07:43:10 +01:00
`
2014-12-31 17:20:53 +01:00
var buildCmd = &warren.Command{
Name: "build",
Usage: "",
Summary: "build the go server in the current directory",
2014-12-10 07:43:10 +01:00
Help: buildUsage,
Run: buildRun,
}
2014-12-31 17:20:53 +01:00
func buildRun(cmd *warren.Command, args ...string) {
2014-12-10 07:43:10 +01:00
if len(args) > 0 && args[0] == "help" {
fmt.Print(cmd.Help)
return
}
date := time.Now().Format(time.RFC3339)
2014-12-12 06:47:29 +01:00
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.BuildDate %s -X main.BuildGitHash %s -X main.BuildGitBranch %s", date, warren.GitHash(), warren.GitBranch()))
2014-12-10 07:43:10 +01:00
gobuild.Stderr = os.Stderr
gobuild.Stdout = os.Stdout
err := gobuild.Run()
2014-12-09 08:54:35 +01:00
if err != nil {
log.Fatal(err)
}
}