From c0e5f8472acb6a397d6b946cea2e5da71b41799a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 28 Nov 2022 21:08:29 -0500 Subject: [PATCH] Version command --- cmd/root.go | 2 ++ cmd/version.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 cmd/version.go diff --git a/cmd/root.go b/cmd/root.go index 0c20413..f7c609b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,8 @@ import ( "github.com/spf13/viper" ) +const VERSION = "0.4.0" + var ( cfgFile string verbose bool diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..d140aa6 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,33 @@ +/* +Copyright © 2022 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "prints command version", + Long: `the version of the ctl command.`, + Run: func(cmd *cobra.Command, args []string) { + versionCobra(cmd, args) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} + +func versionCobra(cmd *cobra.Command, args []string) { + version() +} + +func version() { + fmt.Printf("v%s \n", VERSION) +}