about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-05-08T09·08+0200
committerVincent Ambo <tazjin@gmail.com>2017-05-08T09·15+0200
commitd93bc51e86081c7331554167fbba1318ac9a4927 (patch)
tree7fee5d12b3a0b564b0a1da175af3c7e51518ebdc
parent9b2d102bbf8249a577f9c675b268507c61c3271e (diff)
feat main: Add version command
Adds a version command that can have the Kontemplate git hash added to it at
build time by using the Go linker's -X flag.
-rw-r--r--main.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/main.go b/main.go
index d2aa8209bc53..23b4e6c2c0b5 100644
--- a/main.go
+++ b/main.go
@@ -11,6 +11,10 @@ import (
 	"gopkg.in/alecthomas/kingpin.v2"
 )
 
+const version string = "1.0"
+// This variable will be initialised by the Go linker during the builder
+var gitHash string
+
 type KubeCtlError struct {
 	meep.AllTraits
 }
@@ -38,6 +42,8 @@ var (
 
 	create     = app.Command("create", "Template resources and pass to 'kubectl create'")
 	createFile = create.Arg("file", "Cluster configuration file to use").Required().String()
+
+	versionCmd = app.Command("version", "Show kontemplate version")
 )
 
 func main() {
@@ -58,6 +64,17 @@ func main() {
 
 	case create.FullCommand():
 		createCommand()
+
+	case versionCmd.FullCommand():
+		versionCommand()
+	}
+}
+
+func versionCommand() {
+	if gitHash == "" {
+		fmt.Printf("Kontemplate version %s (git commit unknown)\n", version)
+	} else {
+		fmt.Printf("Kontemplate version %s (git commit: %s)\n", version, gitHash)
 	}
 }