Skip to content

Commit

Permalink
Added bbolt command line version flag to get runtime information.
Browse files Browse the repository at this point in the history
Signed-off-by: Ishan Tyagi <[email protected]>
  • Loading branch information
ishan16696 committed Aug 11, 2023
1 parent b7798fd commit 68ba6d6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/bbolt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cmd/bbolt/command_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewRootCommand() *cobra.Command {
}

rootCmd.AddCommand(
newVersionCobraCommand(),
newSurgeryCobraCommand(),
)

Expand Down
22 changes: 22 additions & 0 deletions cmd/bbolt/command_version.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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,
)
}

0 comments on commit 68ba6d6

Please sign in to comment.