refactor(del): made remove the default case

This commit is contained in:
Lewis Wynne 2025-12-23 09:35:31 +00:00
parent 3d5a3f2aa1
commit c2d1ec0842
21 changed files with 145 additions and 103 deletions

View file

@ -33,9 +33,9 @@ import (
// delStoreCmd represents the set command
var delStoreCmd = &cobra.Command{
Use: "del-store STORE",
Use: "remove-store STORE",
Short: "Delete a store",
Aliases: []string{"delete-store", "rm-store", "remove-store"},
Aliases: []string{"rm-store", "rms"},
Args: cobra.ExactArgs(1),
RunE: delStore,
SilenceUsage: true,

View file

@ -34,9 +34,9 @@ import (
// delCmd represents the set command
var delCmd = &cobra.Command{
Use: "del KEY[@STORE] [KEY[@STORE] ...]",
Use: "remove KEY[@STORE] [KEY[@STORE] ...]",
Short: "Delete one or more keys",
Aliases: []string{"delete", "rm", "remove"},
Aliases: []string{"rm"},
Args: cobra.ArbitraryArgs,
RunE: del,
SilenceUsage: true,

View file

@ -45,9 +45,9 @@ type dumpEntry struct {
}
var dumpCmd = &cobra.Command{
Use: "dump [STORE]",
Use: "export [STORE]",
Short: "Dump all key/value pairs as NDJSON",
Aliases: []string{"export"},
Aliases: []string{"dump"},
Args: cobra.MaximumNArgs(1),
RunE: dump,
SilenceUsage: true,

View file

@ -31,7 +31,7 @@ import (
var listStoresCmd = &cobra.Command{
Use: "list-stores",
Short: "List all stores",
Aliases: []string{"ls-stores", "lsd"},
Aliases: []string{"ls-stores", "lss"},
Args: cobra.NoArgs,
RunE: listStores,
SilenceUsage: true,

View file

@ -31,14 +31,16 @@ import (
)
var cpCmd = &cobra.Command{
Use: "cp FROM[@STORE] TO[@STORE]",
Short: "Make a copy of a key",
Args: cobra.ExactArgs(2),
RunE: cp,
Use: "copy FROM[@STORE] TO[@STORE]",
Aliases: []string{"cp"},
Short: "Make a copy of a key",
Args: cobra.ExactArgs(2),
RunE: cp,
}
var mvCmd = &cobra.Command{
Use: "mv FROM[@STORE] TO[@STORE]",
Use: "move FROM[@STORE] TO[@STORE]",
Aliases: []string{"mv"},
Short: "Move a key",
Args: cobra.ExactArgs(2),
RunE: mv,

View file

@ -36,9 +36,9 @@ import (
)
var restoreCmd = &cobra.Command{
Use: "restore [STORE]",
Use: "import [STORE]",
Short: "Restore key/value pairs from an NDJSON dump",
Aliases: []string{"import"},
Aliases: []string{"restore"},
Args: cobra.MaximumNArgs(1),
RunE: restore,
SilenceUsage: true,

View file

@ -47,4 +47,26 @@ func Execute() {
}
}
func init() {}
func init() {
rootCmd.AddGroup(&cobra.Group{ID: "keys", Title: "Key commands:"})
setCmd.GroupID = "keys"
getCmd.GroupID = "keys"
mvCmd.GroupID = "keys"
cpCmd.GroupID = "keys"
delCmd.GroupID = "keys"
listCmd.GroupID = "keys"
rootCmd.AddGroup(&cobra.Group{ID: "stores", Title: "Store commands:"})
listStoresCmd.GroupID = "stores"
delStoreCmd.GroupID = "stores"
dumpCmd.GroupID = "stores"
restoreCmd.GroupID = "stores"
rootCmd.AddGroup(&cobra.Group{ID: "git", Title: "Git commands:"})
initCmd.GroupID = "git"
syncCmd.GroupID = "git"
gitCmd.GroupID = "git"
}

View file

@ -1,2 +1,2 @@
$ pda del-store foo/bar --> FAIL
$ pda rms foo/bar --> FAIL
Error: cannot delete-store 'foo/bar': cannot parse store: bad store format, use STORE or @STORE

View file

@ -3,7 +3,7 @@ $ pda set bar 2
$ pda ls
bar 2
foo 1
$ pda del foo --glob "*"
$ pda rm foo --glob "*"
$ pda get bar --> FAIL
Error: cannot get 'bar': Key not found
$ pda get foo --> FAIL

View file

@ -1,7 +1,7 @@
$ pda set foo 1
$ pda set bar1 2
$ pda set bar2 3
$ pda del foo --glob bar*
$ pda rm foo --glob bar*
$ pda get foo --> FAIL
Error: cannot get 'foo': Key not found
$ pda get bar1 --> FAIL

View file

@ -1,7 +1,7 @@
$ pda set a1 1
$ pda set a2 2
$ pda set b1 3
$ pda del --glob a*
$ pda rm --glob a*
$ pda get a1 --> FAIL
Error: cannot get 'a1': Key not found
$ pda get a2 --> FAIL

View file

@ -1,6 +1,6 @@
$ pda set a 1
$ pda set b 2
$ pda del a b
$ pda rm a b
$ pda get a --> FAIL
Error: cannot get 'a': Key not found
$ pda get b --> FAIL

2
testdata/del__ok.ct vendored
View file

@ -1,2 +1,2 @@
$ pda set a b
$ pda del a
$ pda rm a

View file

@ -1,24 +1,24 @@
$ pda help del-store
$ pda del-store --help
$ pda help rms
$ pda rms --help
Delete a store
Usage:
pda del-store STORE [flags]
pda remove-store STORE [flags]
Aliases:
del-store, delete-store, rm-store, remove-store
remove-store, rm-store, rms
Flags:
-h, --help help for del-store
-h, --help help for remove-store
-i, --interactive Prompt yes/no for each deletion
Delete a store
Usage:
pda del-store STORE [flags]
pda remove-store STORE [flags]
Aliases:
del-store, delete-store, rm-store, remove-store
remove-store, rm-store, rms
Flags:
-h, --help help for del-store
-h, --help help for remove-store
-i, --interactive Prompt yes/no for each deletion

View file

@ -1,28 +1,28 @@
$ pda help del
$ pda del --help
$ pda help rm
$ pda rm --help
Delete one or more keys
Usage:
pda del KEY[@STORE] [KEY[@STORE] ...] [flags]
pda remove KEY[@STORE] [KEY[@STORE] ...] [flags]
Aliases:
del, delete, rm, remove
remove, rm
Flags:
-g, --glob strings Delete keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for del
-h, --help help for remove
-i, --interactive Prompt yes/no for each deletion
Delete one or more keys
Usage:
pda del KEY[@STORE] [KEY[@STORE] ...] [flags]
pda remove KEY[@STORE] [KEY[@STORE] ...] [flags]
Aliases:
del, delete, rm, remove
remove, rm
Flags:
-g, --glob strings Delete keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for del
-h, --help help for remove
-i, --interactive Prompt yes/no for each deletion

View file

@ -3,28 +3,28 @@ $ pda dump --help
Dump all key/value pairs as NDJSON
Usage:
pda dump [STORE] [flags]
pda export [STORE] [flags]
Aliases:
dump, export
export, dump
Flags:
-e, --encoding string value encoding: auto, base64, or text (default "auto")
-g, --glob strings Filter keys with glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for dump
-h, --help help for export
--secret Include entries marked as secret
Dump all key/value pairs as NDJSON
Usage:
pda dump [STORE] [flags]
pda export [STORE] [flags]
Aliases:
dump, export
export, dump
Flags:
-e, --encoding string value encoding: auto, base64, or text (default "auto")
-g, --glob strings Filter keys with glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for dump
-h, --help help for export
--secret Include entries marked as secret

View file

@ -6,7 +6,7 @@ Usage:
pda list-stores [flags]
Aliases:
list-stores, ls-stores, lsd
list-stores, ls-stores, lss
Flags:
-h, --help help for list-stores
@ -16,7 +16,7 @@ Usage:
pda list-stores [flags]
Aliases:
list-stores, ls-stores, lsd
list-stores, ls-stores, lss
Flags:
-h, --help help for list-stores

80
testdata/help__ok.ct vendored
View file

@ -12,23 +12,29 @@ $ pda --help
Usage:
pda [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
cp Make a copy of a key
del Delete one or more keys
del-store Delete a store
dump Dump all key/value pairs as NDJSON
get Get the value of a key
git Run any arbitrary command. Use with caution.
help Help about any command
init Initialise pda! version control
list List the contents of a store
list-stores List all stores
mv Move a key
restore Restore key/value pairs from an NDJSON dump
set Set a key to a given value
sync Manually sync your stores with Git
version Display pda! version
Key commands:
copy Make a copy of a key
get Get the value of a key
list List the contents of a store
move Move a key
remove Delete one or more keys
set Set a key to a given value
Store commands:
export Dump all key/value pairs as NDJSON
import Restore key/value pairs from an NDJSON dump
list-stores List all stores
remove-store Delete a store
Git commands:
git Run any arbitrary command. Use with caution.
init Initialise pda! version control
sync Manually sync your stores with Git
Additional Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Display pda! version
Flags:
-h, --help help for pda
@ -46,23 +52,29 @@ Use "pda [command] --help" for more information about a command.
Usage:
pda [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
cp Make a copy of a key
del Delete one or more keys
del-store Delete a store
dump Dump all key/value pairs as NDJSON
get Get the value of a key
git Run any arbitrary command. Use with caution.
help Help about any command
init Initialise pda! version control
list List the contents of a store
list-stores List all stores
mv Move a key
restore Restore key/value pairs from an NDJSON dump
set Set a key to a given value
sync Manually sync your stores with Git
version Display pda! version
Key commands:
copy Make a copy of a key
get Get the value of a key
list List the contents of a store
move Move a key
remove Delete one or more keys
set Set a key to a given value
Store commands:
export Dump all key/value pairs as NDJSON
import Restore key/value pairs from an NDJSON dump
list-stores List all stores
remove-store Delete a store
Git commands:
git Run any arbitrary command. Use with caution.
init Initialise pda! version control
sync Manually sync your stores with Git
Additional Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Display pda! version
Flags:
-h, --help help for pda

View file

@ -3,28 +3,28 @@ $ pda restore --help
Restore key/value pairs from an NDJSON dump
Usage:
pda restore [STORE] [flags]
pda import [STORE] [flags]
Aliases:
restore, import
import, restore
Flags:
-f, --file string Path to an NDJSON dump (defaults to stdin)
-g, --glob strings Restore keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for restore
-h, --help help for import
-i, --interactive Prompt before overwriting existing keys
Restore key/value pairs from an NDJSON dump
Usage:
pda restore [STORE] [flags]
pda import [STORE] [flags]
Aliases:
restore, import
import, restore
Flags:
-f, --file string Path to an NDJSON dump (defaults to stdin)
-g, --glob strings Restore keys matching glob pattern (repeatable)
--glob-sep string Characters treated as separators for globbing (default "/-_.@: ")
-h, --help help for restore
-h, --help help for import
-i, --interactive Prompt before overwriting existing keys

View file

@ -2,7 +2,7 @@ $ pda set a1 1
$ pda set a2 2
$ pda set b1 3
$ fecho dumpfile {"key":"a1","value":"1","encoding":"text"} {"key":"a2","value":"2","encoding":"text"} {"key":"b1","value":"3","encoding":"text"}
$ pda del a1 a2 b1
$ pda rm a1 a2 b1
$ pda restore --glob a* --file dumpfile
Restored 2 entries into @default
$ pda get a1

40
testdata/root__ok.ct vendored
View file

@ -11,23 +11,29 @@ $ pda
Usage:
pda [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
cp Make a copy of a key
del Delete one or more keys
del-store Delete a store
dump Dump all key/value pairs as NDJSON
get Get the value of a key
git Run any arbitrary command. Use with caution.
help Help about any command
init Initialise pda! version control
list List the contents of a store
list-stores List all stores
mv Move a key
restore Restore key/value pairs from an NDJSON dump
set Set a key to a given value
sync Manually sync your stores with Git
version Display pda! version
Key commands:
copy Make a copy of a key
get Get the value of a key
list List the contents of a store
move Move a key
remove Delete one or more keys
set Set a key to a given value
Store commands:
export Dump all key/value pairs as NDJSON
import Restore key/value pairs from an NDJSON dump
list-stores List all stores
remove-store Delete a store
Git commands:
git Run any arbitrary command. Use with caution.
init Initialise pda! version control
sync Manually sync your stores with Git
Additional Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Display pda! version
Flags:
-h, --help help for pda