From a051dcd67aea49037446f98ad59bc49961e4aa42 Mon Sep 17 00:00:00 2001 From: Andrew Suderman Date: Fri, 26 Apr 2019 13:03:49 -0600 Subject: [PATCH] Fixing up version command --- Makefile | 5 +++-- cmd/root.go | 7 +++++-- cmd/version.go | 2 +- main.go | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 88ce8d61..c532ee13 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,12 @@ GOBUILD=GO111MODULE=on $(GOCMD) build GOCLEAN=$(GOCMD) clean GOTEST=GO111MODULE=on $(GOCMD) test BINARY_NAME=vpa-analysis -VERSION := $(shell git rev-parse HEAD) +COMMIT := $(shell git rev-parse HEAD) +VERSION := "dev" all: test build build: - $(GOBUILD) -o $(BINARY_NAME) -ldflags "-X main.version=$(VERSION) -s -w" -v + $(GOBUILD) -o $(BINARY_NAME) -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -s -w" -v test: printf "Linter:\n" GO111MODULE=on $(GOCMD) list ./... | xargs -L1 golint | tee golint-report.out diff --git a/cmd/root.go b/cmd/root.go index 7e34b006..0b3fc993 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,7 +29,8 @@ var namespace string var vpaLabels map[string]string var ( - version string + VERSION string + COMMIT string ) func init() { @@ -73,7 +74,9 @@ var rootCmd = &cobra.Command{ } // Execute the stuff -func Execute(version string) { +func Execute(version string, commit string) { + VERSION = version + COMMIT = commit if err := rootCmd.Execute(); err != nil { glog.Error(err) os.Exit(1) diff --git a/cmd/version.go b/cmd/version.go index 9b741f24..7dadddac 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -29,6 +29,6 @@ var versionCmd = &cobra.Command{ Short: "Prints the current version of the tool.", Long: `Prints the current version.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(rootCmd.Use + " " + version) + fmt.Println("Version:" + VERSION + " Commit:" + COMMIT) }, } diff --git a/main.go b/main.go index 3d38d232..5ee00803 100644 --- a/main.go +++ b/main.go @@ -20,9 +20,10 @@ import ( var ( // version is set during build - version = "v0.2.0" + version = "" + commit = "" ) func main() { - cmd.Execute(version) + cmd.Execute(version, commit) }