From d93bc51e86081c7331554167fbba1318ac9a4927 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 8 May 2017 11:08:21 +0200 Subject: [PATCH] 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. --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.go b/main.go index d2aa820..23b4e6c 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) } }