Skip to content

Commit

Permalink
Fixing up version command
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Suderman committed Apr 26, 2019
1 parent aa8d294 commit a051dcd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var namespace string
var vpaLabels map[string]string

var (
version string
VERSION string
COMMIT string
)

func init() {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a051dcd

Please sign in to comment.