From f2a7af30b2305f55ad22b36fd7886c3a75058a2f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 13 Dec 2023 16:26:33 +0100 Subject: [PATCH] [#159] Add version-command for ots-cli Signed-off-by: Knut Ahlers --- cmd/ots-cli/cmd_version.go | 19 +++++++++++++++++++ cmd/ots-cli/main.go | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 cmd/ots-cli/cmd_version.go diff --git a/cmd/ots-cli/cmd_version.go b/cmd/ots-cli/cmd_version.go new file mode 100644 index 0000000..313423f --- /dev/null +++ b/cmd/ots-cli/cmd_version.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Displays the tool version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("ots-cli %s\n", version) //nolint:forbidigo + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/cmd/ots-cli/main.go b/cmd/ots-cli/main.go index 068527e..c7801ea 100644 --- a/cmd/ots-cli/main.go +++ b/cmd/ots-cli/main.go @@ -4,6 +4,8 @@ import ( "os" ) +var version = "dev" + func main() { if err := rootCmd.Execute(); err != nil { os.Exit(1)