-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate bbolt info command to cobra style
Signed-off-by: charles-chenzz <[email protected]>
- Loading branch information
1 parent
a7a791c
commit 96c8323
Showing
3 changed files
with
46 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
bolt "go.etcd.io/bbolt" | ||
) | ||
|
||
func newInfoCommand() *cobra.Command { | ||
infoCmd := &cobra.Command{ | ||
Use: "bolt info PATH", | ||
Short: "Info prints basic information about the Bolt database at PATH.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
path := args[0] | ||
if path == "" { | ||
return ErrPathRequired | ||
} else if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return ErrFileNotFound | ||
} | ||
|
||
// Open the database. | ||
db, err := bolt.Open(path, 0666, &bolt.Options{ReadOnly: true}) | ||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
|
||
// Print basic database info. | ||
info := db.Info() | ||
fmt.Fprintf(os.Stdout, "Page size: %d\n", info.PageSize) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
fs := pflag.NewFlagSet("", pflag.ContinueOnError) | ||
fs.Bool("h", false, "") | ||
|
||
infoCmd.Flags().AddFlagSet(fs) | ||
|
||
return infoCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters