feat(rm): adds --yes flag to auto-accept all prompts
This commit is contained in:
parent
cf7dbf5bee
commit
9130c09e56
4 changed files with 19 additions and 1 deletions
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
2
testdata/help-remove.ct
vendored
2
testdata/help-remove.ct
vendored
|
|
@ -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
8
testdata/remove-yes.ct
vendored
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue