Skip to content

Commit

Permalink
add "version" command to display git version string (#221)
Browse files Browse the repository at this point in the history
* add "version" command to display git version string

* drop unused parameter
  • Loading branch information
kdomanski authored and kubermatic-bot committed Mar 1, 2019
1 parent d585b9d commit 805b686
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export TFJSON?=
export KUBEONE_CONFIG_FILE?=config.yaml.dist
export KUBERNETES_VERSION=1.13.3
BUILD_IMAGE?=golang:1.11.5
GOLDFLAGS?=-w -s
GITTAG=$(shell git describe --tags --always)
GOLDFLAGS?=-w -s -X github.com/kubermatic/kubeone/pkg/cmd.versionString=$(GITTAG)

PROVIDER=$(notdir $(wildcard ./terraform/*))
CREATE_TARGETS=$(addsuffix -env,$(PROVIDER))
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newRoot() *cobra.Command {
upgradeCmd(fs),
resetCmd(fs),
kubeconfigCmd(fs),
versionCmd(fs),
)

return rootCmd
Expand Down
26 changes: 26 additions & 0 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var versionString = "development"

// versionCmd setups version command
func versionCmd(_ *pflag.FlagSet) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Display KubeOne version",
Long: `Prints the exact version number, as embedded by the build system.`,
Args: cobra.ExactArgs(0),
RunE: func(_ *cobra.Command, args []string) error {
fmt.Printf("KubeOne %s\n", versionString)
return nil
},
}

return cmd
}

0 comments on commit 805b686

Please sign in to comment.