diff --git a/cmd/del.go b/cmd/del.go index 844352a..8979c9c 100644 --- a/cmd/del.go +++ b/cmd/del.go @@ -66,6 +66,10 @@ func del(cmd *cobra.Command, args []string) error { return err } + if len(targetKeys) == 0 { + return fmt.Errorf("cannot remove: No such key") + } + if !force { var confirm string quotedTargets := make([]string, 0, len(targetKeys)) @@ -153,14 +157,13 @@ func resolveDeleteTargets(store *Store, exactArgs []string, globPatterns []strin var targetKeys []string var deleteTargets []string - var matched bool for _, arg := range exactArgs { exists, err := keyExists(store, arg) if err != nil { return nil, nil, fmt.Errorf("cannot remove '%s': %v", arg, err) } if !exists { - return nil, nil, fmt.Errorf("cannot remove '%s': No such key", arg) + continue } formatted, err := formatKeyForPrompt(store, arg) if err != nil { @@ -170,7 +173,6 @@ func resolveDeleteTargets(store *Store, exactArgs []string, globPatterns []strin targetSet[arg] = struct{}{} targetKeys = append(targetKeys, formatted) deleteTargets = append(deleteTargets, arg) - matched = true } } @@ -233,14 +235,9 @@ func resolveDeleteTargets(store *Store, exactArgs []string, globPatterns []strin } targetKeys = append(targetKeys, display) deleteTargets = append(deleteTargets, full) - matched = true } } } - if len(globPatterns) > 0 && !matched { - return nil, nil, fmt.Errorf("cannot remove '%s': No matches for pattern", globPatterns[0]) - } - return targetKeys, deleteTargets, nil } diff --git a/cmd/dump.go b/cmd/dump.go index 2750225..e1048bb 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -142,7 +142,7 @@ func dump(cmd *cobra.Command, args []string) error { } if len(matchers) > 0 && !matched { - return fmt.Errorf("cannot dump '%s': No matches for pattern", displayTarget) + return fmt.Errorf("cannot dump '%s': No matches for pattern %s", displayTarget, formatGlobPatterns(globPatterns)) } return nil } diff --git a/cmd/glob.go b/cmd/glob.go index 5a7bb7e..a985aae 100644 --- a/cmd/glob.go +++ b/cmd/glob.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "strings" "github.com/gobwas/glob" @@ -52,3 +53,11 @@ func globMatch(matchers []glob.Glob, key string) bool { } return false } + +func formatGlobPatterns(patterns []string) string { + quoted := make([]string, 0, len(patterns)) + for _, pattern := range patterns { + quoted = append(quoted, fmt.Sprintf("'%s'", pattern)) + } + return strings.Join(quoted, ", ") +} diff --git a/cmd/list.go b/cmd/list.go index 10f2db4..04c4af5 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -162,7 +162,7 @@ func list(cmd *cobra.Command, args []string) error { } if len(matchers) > 0 && matchedCount == 0 { - return fmt.Errorf("cannot ls '%s': No matches for pattern", targetDB) + return fmt.Errorf("cannot ls '%s': No matches for pattern %s", targetDB, formatGlobPatterns(globPatterns)) } applyColumnConstraints(tw, columnKinds, output, maxContentWidths) diff --git a/cmd/restore.go b/cmd/restore.go index 8926416..58dfe8e 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -116,7 +116,7 @@ func restore(cmd *cobra.Command, args []string) error { } if len(matchers) > 0 && !matched { - return fmt.Errorf("cannot restore '%s': No matches for pattern", displayTarget) + return fmt.Errorf("cannot restore '%s': No matches for pattern %s", displayTarget, formatGlobPatterns(globPatterns)) } fmt.Fprintf(cmd.ErrOrStderr(), "Restored %d entries into @%s\n", restored, dbName) diff --git a/testdata/dump__glob__ok.ct b/testdata/dump__glob__ok.ct index 7d1ce79..a0a0525 100644 --- a/testdata/dump__glob__ok.ct +++ b/testdata/dump__glob__ok.ct @@ -5,4 +5,4 @@ $ pda dump --glob a* {"key":"a1","value":"1","encoding":"text"} {"key":"a2","value":"2","encoding":"text"} $ pda dump --glob c* --> FAIL -Error: cannot dump '@default': No matches for pattern +Error: cannot dump '@default': No matches for pattern 'c*' diff --git a/testdata/list__glob__ok.ct b/testdata/list__glob__ok.ct index 4dcba80..924d72c 100644 --- a/testdata/list__glob__ok.ct +++ b/testdata/list__glob__ok.ct @@ -7,4 +7,4 @@ a2 2 $ pda ls lg --glob b* --format tsv b1 3 $ pda ls lg --glob c* --> FAIL -Error: cannot ls '@lg': No matches for pattern +Error: cannot ls '@lg': No matches for pattern 'c*' diff --git a/testdata/restore__glob__ok.ct b/testdata/restore__glob__ok.ct index 3394d26..c23dfd3 100644 --- a/testdata/restore__glob__ok.ct +++ b/testdata/restore__glob__ok.ct @@ -12,4 +12,4 @@ $ pda get a2 $ pda get b1 --> FAIL Error: cannot get 'b1': Key not found $ pda restore --glob c* --file dumpfile --> FAIL -Error: cannot restore '@default': No matches for pattern +Error: cannot restore '@default': No matches for pattern 'c*'