feat(rm): adds --yes flag to auto-accept all prompts

This commit is contained in:
Lewis Wynne 2026-02-11 17:57:05 +00:00
parent cf7dbf5bee
commit 9130c09e56
4 changed files with 19 additions and 1 deletions

View file

@ -197,6 +197,9 @@ pda rm kitty --key "?og"
pda rm kitty -i
# ??? remove 'kitty'? (y/n)
# ==> y
# --yes/-y to auto-accept all confirmation prompts.
pda rm kitty -y
```
<p align="center"></p><!-- spacer -->

View file

@ -47,6 +47,10 @@ func del(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
yes, err := cmd.Flags().GetBool("yes")
if err != nil {
return err
}
keyPatterns, err := cmd.Flags().GetStringSlice("key")
if err != nil {
return err
@ -72,7 +76,7 @@ func del(cmd *cobra.Command, args []string) error {
byStore := make(map[string]*storeTargets)
var storeOrder []string
for _, target := range targets {
if interactive || config.Key.AlwaysPromptDelete {
if !yes && (interactive || config.Key.AlwaysPromptDelete) {
var confirm string
promptf("remove '%s'? (y/n)", target.display)
if err := scanln(&confirm); err != nil {
@ -120,6 +124,7 @@ func del(cmd *cobra.Command, args []string) error {
func init() {
delCmd.Flags().BoolP("interactive", "i", false, "Prompt yes/no for each deletion")
delCmd.Flags().BoolP("yes", "y", false, "Skip all confirmation prompts")
delCmd.Flags().StringSliceP("key", "k", nil, "Delete keys matching glob pattern (repeatable)")
rootCmd.AddCommand(delCmd)
}

View file

@ -12,6 +12,7 @@ Flags:
-h, --help help for remove
-i, --interactive Prompt yes/no for each deletion
-k, --key strings Delete keys matching glob pattern (repeatable)
-y, --yes Skip all confirmation prompts
Delete one or more keys
Usage:
@ -24,3 +25,4 @@ Flags:
-h, --help help for remove
-i, --interactive Prompt yes/no for each deletion
-k, --key strings Delete keys matching glob pattern (repeatable)
-y, --yes Skip all confirmation prompts

8
testdata/remove-yes.ct vendored Normal file
View file

@ -0,0 +1,8 @@
$ pda set a@ry "1"
$ pda set b@ry "2"
$ pda rm a@ry -i -y
$ pda get a@ry --> FAIL
FAIL cannot get 'a@ry': no such key
hint did you mean 'b'?
$ pda get b@ry
"2"