From 64341a81faf52921d3c31a7ca8985d0a7097ab6f Mon Sep 17 00:00:00 2001 From: Liviu Costea Date: Fri, 16 Aug 2019 09:46:37 +0300 Subject: [PATCH] Add short version flag --- pkg/commands/misc/version.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/commands/misc/version.go b/pkg/commands/misc/version.go index e9dbe9e59..1d78865c3 100644 --- a/pkg/commands/misc/version.go +++ b/pkg/commands/misc/version.go @@ -59,18 +59,28 @@ func getVersion() version { } // Print prints version. -func (v version) Print(w io.Writer) { - fmt.Fprintf(w, "Version: %+v\n", v) +func (v version) Print(w io.Writer, short bool) { + if short { + fmt.Fprintf(w, "%s\n", v.KustomizeVersion) + } else { + fmt.Fprintf(w, "Version: %+v\n", v) + } + } // NewCmdVersion makes version command. func NewCmdVersion(w io.Writer) *cobra.Command { - return &cobra.Command{ + var short bool + + versionCmd := cobra.Command{ Use: "version", Short: "Prints the kustomize version", Example: `kustomize version`, Run: func(cmd *cobra.Command, args []string) { - getVersion().Print(w) + getVersion().Print(w, short) }, } + + versionCmd.Flags().BoolVar(&short, "short", false, "print just the version number") + return &versionCmd }