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 // delStoreCmd represents the set command
var delStoreCmd = &cobra.Command{ var delStoreCmd = &cobra.Command{
Use: "del-store STORE", Use: "remove-store STORE",
Short: "Delete a store", Short: "Delete a store",
Aliases: []string{"delete-store", "rm-store", "remove-store"}, Aliases: []string{"rm-store", "rms"},
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: delStore, RunE: delStore,
SilenceUsage: true, SilenceUsage: true,

View file

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

View file

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

View file

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

View file

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

View file

@ -36,9 +36,9 @@ import (
) )
var restoreCmd = &cobra.Command{ var restoreCmd = &cobra.Command{
Use: "restore [STORE]", Use: "import [STORE]",
Short: "Restore key/value pairs from an NDJSON dump", Short: "Restore key/value pairs from an NDJSON dump",
Aliases: []string{"import"}, Aliases: []string{"restore"},
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
RunE: restore, RunE: restore,
SilenceUsage: true, 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 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 $ pda ls
bar 2 bar 2
foo 1 foo 1
$ pda del foo --glob "*" $ pda rm foo --glob "*"
$ pda get bar --> FAIL $ pda get bar --> FAIL
Error: cannot get 'bar': Key not found Error: cannot get 'bar': Key not found
$ pda get foo --> FAIL $ pda get foo --> FAIL

View file

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

View file

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

View file

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

2
testdata/del__ok.ct vendored
View file

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

View file

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

View file

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

View file

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

View file

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

80
testdata/help__ok.ct vendored
View file

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

View file

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

View file

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

40
testdata/root__ok.ct vendored
View file

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