Skip to content

Commit efb0e81

Browse files
Merge pull request #4 from jskswamy/version
Add cmd to show version
2 parents 2f31cda + de85afd commit efb0e81

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ help: ## prints help (only for tasks with comment)
55
APP=kube-tmuxp
66
SRC_PACKAGES=$(shell go list ./...)
77
APP_EXECUTABLE="./out/$(APP)"
8+
BUILD?=$(shell git describe --tags --always --dirty)
89
RICHGO=$(shell command -v richgo 2> /dev/null)
910

1011
ifeq ($(RICHGO),)
@@ -22,10 +23,10 @@ modules: ## add missing and remove unused modules
2223
go mod tidy
2324

2425
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
2627

2728
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
2930

3031
fmt: ## format go code
3132
$(GOBIN) fmt $(SRC_PACKAGES)

cmd/version.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

main.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package main
22

33
import "github.com/arunvelsriram/kube-tmuxp/cmd"
44

5+
var version string
6+
57
func main() {
8+
cmd.SetVersion(version)
69
cmd.Execute()
710
}

0 commit comments

Comments
 (0)