From 7c38d9ae714b6f04419cbb31dc24a4dcc444aa17 Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Mon, 12 Jun 2023 20:22:55 -0400 Subject: [PATCH] trying to implement a version command --- cmd/obp/cmd/version.go | 33 +++++++++++++++++++++++++++++++++ cmd/obp/main.go | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 cmd/obp/cmd/version.go diff --git a/cmd/obp/cmd/version.go b/cmd/obp/cmd/version.go new file mode 100644 index 0000000..8bc1f21 --- /dev/null +++ b/cmd/obp/cmd/version.go @@ -0,0 +1,33 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + Version, Tag string +) + +// rootCmd represents the base command when called without any subcommands +var versionCmd = &cobra.Command{ + Use: "version", + Short: "prints obp version info", + Long: `displays git tag and sha +`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("%s %s\n", Version, Tag) + }, +} + +func init() { + // Cobra also supports local flags, which will only run + // when this action is called directly. + // rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.AddCommand(versionCmd) + +} diff --git a/cmd/obp/main.go b/cmd/obp/main.go index 4d40280..cf7dddf 100644 --- a/cmd/obp/main.go +++ b/cmd/obp/main.go @@ -10,5 +10,7 @@ var ( ) func main() { + cmd.Version = Version + cmd.Tag = Tag cmd.Execute() }