From a908c24235564339d8686c142f01493d3bc7d7f2 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 17 Aug 2017 23:40:28 +0100 Subject: [PATCH] Use linker flags to set git commit in version command --- Makefile | 6 ++++-- client/commands/version.go | 5 ++++- cmd/baseserver/main.go | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 30b1e589af..b4fbf32ae1 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/client/commands/version.go b/client/commands/version.go index 9ffa6b36dc..34a2af2ff1 100644 --- a/client/commands/version.go +++ b/client/commands/version.go @@ -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) }, } diff --git a/cmd/baseserver/main.go b/cmd/baseserver/main.go index 27cb14b8c2..fee1552a33 100644 --- a/cmd/baseserver/main.go +++ b/cmd/baseserver/main.go @@ -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)