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() }