feat(cmd): silence mvCmd usage on err and improved err msging
This commit is contained in:
parent
3a4dd11acb
commit
221d4cd921
1 changed files with 7 additions and 6 deletions
13
cmd/mv.go
13
cmd/mv.go
|
|
@ -15,10 +15,11 @@ var cpCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var mvCmd = &cobra.Command{
|
var mvCmd = &cobra.Command{
|
||||||
Use: "mv FROM[@DB] TO[@DB]",
|
Use: "mv FROM[@DB] TO[@DB]",
|
||||||
Short: "Move a key between (or within) databases.",
|
Short: "Move a key between (or within) databases.",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: mv,
|
RunE: mv,
|
||||||
|
SilenceUsage: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func cp(cmd *cobra.Command, args []string) error {
|
func cp(cmd *cobra.Command, args []string) error {
|
||||||
|
|
@ -47,7 +48,7 @@ func mv(cmd *cobra.Command, args []string) error {
|
||||||
transact: func(tx *badger.Txn, k []byte) error {
|
transact: func(tx *badger.Txn, k []byte) error {
|
||||||
item, err := tx.Get(k)
|
item, err := tx.Get(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("cannot move '%s': %v", fromKey, err)
|
||||||
}
|
}
|
||||||
srcMeta = item.UserMeta()
|
srcMeta = item.UserMeta()
|
||||||
srcExpires = item.ExpiresAt()
|
srcExpires = item.ExpiresAt()
|
||||||
|
|
@ -68,7 +69,7 @@ func mv(cmd *cobra.Command, args []string) error {
|
||||||
transact: func(tx *badger.Txn, k []byte) error {
|
transact: func(tx *badger.Txn, k []byte) error {
|
||||||
if !force {
|
if !force {
|
||||||
if _, err := tx.Get(k); err == nil {
|
if _, err := tx.Get(k); err == nil {
|
||||||
return fmt.Errorf("%q already exists; run again with --force to overwrite it", args[1])
|
return fmt.Errorf("cannot move '%s': '%s' already exists > run with --force to overwrite", fromKey, toKey)
|
||||||
} else if err != badger.ErrKeyNotFound {
|
} else if err != badger.ErrKeyNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue