Use linker flags to set git commit in version command

This commit is contained in:
Ethan Frey 2017-08-17 23:40:28 +01:00
parent 27d86c7769
commit a908c24235
3 changed files with 11 additions and 5 deletions

View File

@ -3,14 +3,16 @@ GOTOOLS = github.com/mitchellh/gox \
github.com/rigelrozanski/shelldown/cmd/shelldown
TUTORIALS=$(shell find docs/guide -name "*md" -type f)
LINKER_FLAGS:="-X github.com/tendermint/basecoin/client/commands.CommitHash=`git rev-parse --short HEAD`"
all: get_vendor_deps install test
build:
@go build ./cmd/...
install:
@go install ./cmd/...
@go install ./docs/guide/counter/cmd/...
@go install -ldflags $(LINKER_FLAGS) ./cmd/...
@go install -ldflags $(LINKER_FLAGS) ./docs/guide/counter/cmd/...
dist:
@bash publish/dist.sh

View File

@ -7,11 +7,14 @@ import (
"github.com/tendermint/basecoin/version"
)
// CommitHash should be filled by linker flags
var CommitHash = ""
// VersionCmd - command to show the application version
var VersionCmd = &cobra.Command{
Use: "version",
Short: "Show version info",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.Version)
fmt.Printf("v%s %s\n", version.Version, CommitHash)
},
}

View File

@ -74,11 +74,12 @@ func main() {
srvCli.AddCommand(
commands.InitCmd,
commands.VersionCmd,
serveCmd,
)
// TODO: Decide whether to use $HOME/.basecli for compatibility
// or just use $HOME/.baseserver?
// this should share the dir with basecli, so you can use the cli and
// the api interchangeably
cmd := cli.PrepareMainCmd(srvCli, "BC", os.ExpandEnv("$HOME/.basecli"))
if err := cmd.Execute(); err != nil {
log.Fatal(err)