Add version command that prints compiled version

Fix #128
This commit is contained in:
Justin Santa Barbara 2016-07-12 22:29:57 -04:00
parent 2cdd4a5e16
commit d77d6f4859
2 changed files with 47 additions and 1 deletions

View File

@ -3,8 +3,12 @@ all: gocode
DOCKER_REGISTRY=gcr.io/must-override/
S3_BUCKET=s3://must-override/
ifndef VERSION
VERSION := git-$(shell git rev-parse --short HEAD)
endif
gocode:
GO15VENDOREXPERIMENT=1 go install k8s.io/kops/cmd/...
GO15VENDOREXPERIMENT=1 go install -ldflags "-X main.BuildVersion=${VERSION}" k8s.io/kops/cmd/...
ln -sfn ${GOPATH}/src/k8s.io/kops/upup/models/ ${GOPATH}/bin/models
codegen:

42
cmd/kops/version.go Normal file
View File

@ -0,0 +1,42 @@
package main
import (
"github.com/spf13/cobra"
"github.com/golang/glog"
"fmt"
)
var (
// value overwritten during build. This can be used to resolve issues.
BuildVersion = "0.1"
)
type VersionCmd struct {
cobraCommand *cobra.Command
}
var versionCmd = VersionCmd{
cobraCommand: &cobra.Command{
Use: "version",
Short: "Print the client version information",
},
}
func init() {
cmd := versionCmd.cobraCommand
rootCommand.cobraCommand.AddCommand(cmd)
cmd.Run = func(cmd *cobra.Command, args []string) {
err := versionCmd.Run()
if err != nil {
glog.Exitf("%v", err)
}
}
}
func (c *VersionCmd) Run() error {
fmt.Printf("Version %s\n", BuildVersion)
return nil
}