File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ help: ## prints help (only for tasks with comment)
55APP =kube-tmuxp
66SRC_PACKAGES =$(shell go list ./...)
77APP_EXECUTABLE ="./out/$(APP ) "
8+ BUILD? =$(shell git describe --tags --always --dirty)
89RICHGO =$(shell command -v richgo 2> /dev/null)
910
1011ifeq ($(RICHGO ) ,)
@@ -22,10 +23,10 @@ modules: ## add missing and remove unused modules
2223 go mod tidy
2324
2425compile : ensure-out-dir # # compiles kube-tmuxp for this platform
25- $(GOBIN ) build -o $(APP_EXECUTABLE ) ./main.go
26+ $(GOBIN ) build -ldflags " -X main.version= ${BUILD} " - o $(APP_EXECUTABLE ) ./main.go
2627
2728compile-linux : ensure-out-dir # # compiles kube-tmuxp for linux
28- GOOS=linux GOARCH=amd64 $(GOBIN ) build -o $(APP_EXECUTABLE ) ./main.go
29+ GOOS=linux GOARCH=amd64 $(GOBIN ) build -ldflags " -X main.version= ${BUILD} " - o $(APP_EXECUTABLE ) ./main.go
2930
3031fmt : # # format go code
3132 $(GOBIN ) fmt $(SRC_PACKAGES )
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/spf13/cobra"
7+ )
8+
9+ var buildVersion string
10+
11+ // SetVersion set the major and minor version
12+ func SetVersion (version string ) {
13+ buildVersion = version
14+ }
15+
16+ var versionCmd = & cobra.Command {
17+ Use : "version" ,
18+ Short : "Print the current version" ,
19+ Run : func (cmd * cobra.Command , args []string ) {
20+ fmt .Println (buildVersion )
21+ },
22+ }
23+
24+ func init () {
25+ rootCmd .AddCommand (versionCmd )
26+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ package main
22
33import "github.com/arunvelsriram/kube-tmuxp/cmd"
44
5+ var version string
6+
57func main () {
8+ cmd .SetVersion (version )
69 cmd .Execute ()
710}
You can’t perform that action at this time.
0 commit comments