Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use cobra exactArgs #728

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions cmd/bbolt/command_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"os"

Expand All @@ -15,15 +14,7 @@ func newInspectCobraCommand() *cobra.Command {
inspectCmd := &cobra.Command{
Use: "inspect",
Short: "inspect the structure of the database",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return inspectFunc(args[0])
},
Expand Down
40 changes: 4 additions & 36 deletions cmd/bbolt/command_surgery.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ func newSurgeryRevertMetaPageCommand() *cobra.Command {
revertMetaPageCmd := &cobra.Command{
Use: "revert-meta-page <bbolt-file> [options]",
Short: "Revert the meta page to revert the changes performed by the latest transaction",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down Expand Up @@ -121,15 +113,7 @@ func newSurgeryCopyPageCommand() *cobra.Command {
copyPageCmd := &cobra.Command{
Use: "copy-page <bbolt-file> [options]",
Short: "Copy page from the source page Id to the destination page Id",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down Expand Up @@ -193,15 +177,7 @@ func newSurgeryClearPageCommand() *cobra.Command {
clearPageCmd := &cobra.Command{
Use: "clear-page <bbolt-file> [options]",
Short: "Clears all elements from the given page, which can be a branch or leaf page",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down Expand Up @@ -268,15 +244,7 @@ func newSurgeryClearPageElementsCommand() *cobra.Command {
clearElementCmd := &cobra.Command{
Use: "clear-page-elements <bbolt-file> [options]",
Short: "Clears elements from the given page, which can be a branch or leaf page",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down
21 changes: 2 additions & 19 deletions cmd/bbolt/command_surgery_freelist.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -29,15 +28,7 @@ func newSurgeryFreelistAbandonCommand() *cobra.Command {
abandonFreelistCmd := &cobra.Command{
Use: "abandon <bbolt-file> [options]",
Short: "Abandon the freelist from both meta pages",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down Expand Up @@ -72,15 +63,7 @@ func newSurgeryFreelistRebuildCommand() *cobra.Command {
rebuildFreelistCmd := &cobra.Command{
Use: "rebuild <bbolt-file> [options]",
Short: "Rebuild the freelist",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down
21 changes: 2 additions & 19 deletions cmd/bbolt/command_surgery_meta.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -37,15 +36,7 @@ func newSurgeryMetaValidateCommand() *cobra.Command {
metaValidateCmd := &cobra.Command{
Use: "validate <bbolt-file> [options]",
Short: "Validate both meta pages",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return surgeryMetaValidateFunc(args[0])
},
Expand Down Expand Up @@ -131,15 +122,7 @@ func newSurgeryMetaUpdateCommand() *cobra.Command {
metaUpdateCmd := &cobra.Command{
Use: "update <bbolt-file> [options]",
Short: "Update fields in meta pages",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("db file path not provided")
}
if len(args) > 1 {
return errors.New("too many arguments")
}
return nil
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Validate(); err != nil {
return err
Expand Down
Loading