From 68ba6d6c90f95c4405c05d03598c24186760bcd7 Mon Sep 17 00:00:00 2001 From: Ishan Tyagi Date: Fri, 11 Aug 2023 15:47:18 +0530 Subject: [PATCH] Added bbolt command line version flag to get runtime information. Signed-off-by: Ishan Tyagi --- cmd/bbolt/README.md | 16 ++++++++++++++++ cmd/bbolt/command_root.go | 1 + cmd/bbolt/command_version.go | 22 ++++++++++++++++++++++ cmd/bbolt/main.go | 1 + version/version.go | 19 +++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 cmd/bbolt/command_version.go create mode 100644 version/version.go diff --git a/cmd/bbolt/README.md b/cmd/bbolt/README.md index 851f380ba..8c7785456 100644 --- a/cmd/bbolt/README.md +++ b/cmd/bbolt/README.md @@ -40,6 +40,7 @@ The commands are: + version prints the current version of bbolt bench run synthetic benchmark against bbolt buckets print a list of buckets check verifies integrity of bbolt database @@ -60,6 +61,21 @@ ## Analyse bbolt database with bbolt command line +### version + +- `version` print the current version information of bbolt command-line. +- usage: + `bbolt version` + + Example: + + ```bash + $bbolt version + bbolt version: 1.3.7 + Go Version: go1.20.7 + Go OS/Arch: darwin/arm64 + ``` + ### info - `info` print the basic information about the given Bbolt database. diff --git a/cmd/bbolt/command_root.go b/cmd/bbolt/command_root.go index b960df898..31a174080 100644 --- a/cmd/bbolt/command_root.go +++ b/cmd/bbolt/command_root.go @@ -17,6 +17,7 @@ func NewRootCommand() *cobra.Command { } rootCmd.AddCommand( + newVersionCobraCommand(), newSurgeryCobraCommand(), ) diff --git a/cmd/bbolt/command_version.go b/cmd/bbolt/command_version.go new file mode 100644 index 000000000..cfa1cf583 --- /dev/null +++ b/cmd/bbolt/command_version.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "go.etcd.io/bbolt/version" +) + +func newVersionCobraCommand() *cobra.Command { + versionCmd := &cobra.Command{ + Use: "version", + Short: "print the current version of bbolt", + Long: "print the current version of bbolt", + Run: func(cmd *cobra.Command, args []string) { + fmt.Fprintln(os.Stdout, version.PrintVersionInfo()) + }, + } + + return versionCmd +} diff --git a/cmd/bbolt/main.go b/cmd/bbolt/main.go index 364b1fe21..7115471c0 100644 --- a/cmd/bbolt/main.go +++ b/cmd/bbolt/main.go @@ -156,6 +156,7 @@ Usage: The commands are: + version print the current version of bbolt bench run synthetic benchmark against bbolt buckets print a list of buckets check verifies integrity of bbolt database diff --git a/version/version.go b/version/version.go new file mode 100644 index 000000000..8191f6235 --- /dev/null +++ b/version/version.go @@ -0,0 +1,19 @@ +package version + +import ( + "fmt" + "runtime" +) + +var ( + // Version shows the last bbolt binary version released. + Version = "1.3.7" +) + +// PrintVersionInfo prints the information regrading version. +func PrintVersionInfo() string { + return fmt.Sprintf( + "bbolt version: %s \nGo Version: %s \nGo OS/Arch: %s/%s", + Version, runtime.Version(), runtime.GOOS, runtime.GOARCH, + ) +}