From 862dedc028bce5ce8fbb931e35c0dcf584af4d90 Mon Sep 17 00:00:00 2001 From: Raullen Chai Date: Fri, 10 Nov 2023 15:53:49 -0800 Subject: [PATCH] Create version.go --- cmd/wsctl/cmd/version.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cmd/wsctl/cmd/version.go diff --git a/cmd/wsctl/cmd/version.go b/cmd/wsctl/cmd/version.go new file mode 100644 index 00000000..1f1ff8c5 --- /dev/null +++ b/cmd/wsctl/cmd/version.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// Version is set during build time using -ldflags +var Version string + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number of wsctl", + Long: `All software has versions. This is wsctl's version.`, + Run: func(cmd *cobra.Command, args []string) { + if Version == "" { + Version = "development" // default version if not set during build + } + fmt.Printf("wsctl version: %s\n", Version) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}