diff --git a/Makefile b/Makefile index bebae706c3..e8353ab86e 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/cmd/kops/version.go b/cmd/kops/version.go new file mode 100644 index 0000000000..3fea4c0616 --- /dev/null +++ b/cmd/kops/version.go @@ -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 +} +