feat(Store): extracted suggestion logic into a helper so we can share it between list and delete-dbs

This commit is contained in:
Lewis Wynne 2025-11-06 22:52:14 +00:00
parent fa224d9b38
commit 0b980ed9dc
2 changed files with 43 additions and 20 deletions

View file

@ -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, &notFound) {
return fmt.Errorf("%q does not exist, %s", rawArg, err.Error())
}
return err
}
targetDB = "@" + dbName
}