feat(Store): extracted suggestion logic into a helper so we can share it between list and delete-dbs
This commit is contained in:
parent
fa224d9b38
commit
0b980ed9dc
2 changed files with 43 additions and 20 deletions
13
cmd/list.go
13
cmd/list.go
|
|
@ -22,6 +22,9 @@ THE SOFTWARE.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -38,10 +41,18 @@ func list(cmd *cobra.Command, args []string) error {
|
|||
store := &Store{}
|
||||
targetDB := "@default"
|
||||
if len(args) == 1 {
|
||||
dbName, err := store.parseDB(args[0], false)
|
||||
rawArg := args[0]
|
||||
dbName, err := store.parseDB(rawArg, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := store.FindStore(dbName); err != nil {
|
||||
var notFound errNotFound
|
||||
if errors.As(err, ¬Found) {
|
||||
return fmt.Errorf("%q does not exist, %s", rawArg, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
targetDB = "@" + dbName
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue