File tree 3 files changed +32
-2
lines changed
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)
5
5
APP =kube-tmuxp
6
6
SRC_PACKAGES =$(shell go list ./...)
7
7
APP_EXECUTABLE ="./out/$(APP ) "
8
+ BUILD? =$(shell git describe --tags --always --dirty)
8
9
RICHGO =$(shell command -v richgo 2> /dev/null)
9
10
10
11
ifeq ($(RICHGO ) ,)
@@ -22,10 +23,10 @@ modules: ## add missing and remove unused modules
22
23
go mod tidy
23
24
24
25
compile : 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
26
27
27
28
compile-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
29
30
30
31
fmt : # # format go code
31
32
$(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
2
2
3
3
import "github.com/arunvelsriram/kube-tmuxp/cmd"
4
4
5
+ var version string
6
+
5
7
func main () {
8
+ cmd .SetVersion (version )
6
9
cmd .Execute ()
7
10
}
You can’t perform that action at this time.
0 commit comments