Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
feat main: Add version command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tazjin committed May 8, 2017
1 parent 9b2d102 commit d93bc51
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit d93bc51

Please sign in to comment.