From c2d1ec08422461d33bd6fce6b0fb6b6e2b75d786 Mon Sep 17 00:00:00 2001 From: lew Date: Tue, 23 Dec 2025 09:35:31 +0000 Subject: [PATCH] refactor(del): made remove the default case --- cmd/del-db.go | 4 +- cmd/del.go | 4 +- cmd/dump.go | 4 +- cmd/list-dbs.go | 2 +- cmd/mv.go | 12 ++-- cmd/restore.go | 4 +- cmd/root.go | 24 ++++++- testdata/del-db__err__with__invalid_db.ct | 2 +- testdata/del__dedupe__ok.ct | 2 +- testdata/del__glob__mixed__ok.ct | 2 +- testdata/del__glob__ok.ct | 2 +- testdata/del__multiple__ok.ct | 2 +- testdata/del__ok.ct | 2 +- testdata/help__del-db__ok.ct | 16 ++--- testdata/help__del__ok.ct | 16 ++--- testdata/help__dump__ok.ct | 12 ++-- testdata/help__list-dbs__ok.ct | 4 +- testdata/help__ok.ct | 80 +++++++++++++---------- testdata/help__restore__ok.ct | 12 ++-- testdata/restore__glob__ok.ct | 2 +- testdata/root__ok.ct | 40 +++++++----- 21 files changed, 145 insertions(+), 103 deletions(-) diff --git a/cmd/del-db.go b/cmd/del-db.go index cc5d425..a1ac5ff 100644 --- a/cmd/del-db.go +++ b/cmd/del-db.go @@ -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, diff --git a/cmd/del.go b/cmd/del.go index ad27031..640dcfd 100644 --- a/cmd/del.go +++ b/cmd/del.go @@ -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, diff --git a/cmd/dump.go b/cmd/dump.go index 060f6ce..4db2134 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -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, diff --git a/cmd/list-dbs.go b/cmd/list-dbs.go index 633f0c9..7e36f29 100644 --- a/cmd/list-dbs.go +++ b/cmd/list-dbs.go @@ -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, diff --git a/cmd/mv.go b/cmd/mv.go index 4dc1c75..78ae581 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -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, diff --git a/cmd/restore.go b/cmd/restore.go index 7e994f7..9cd75b7 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -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, diff --git a/cmd/root.go b/cmd/root.go index 4f01fe0..82a269d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" +} diff --git a/testdata/del-db__err__with__invalid_db.ct b/testdata/del-db__err__with__invalid_db.ct index 4d8a1e1..9d99bf7 100644 --- a/testdata/del-db__err__with__invalid_db.ct +++ b/testdata/del-db__err__with__invalid_db.ct @@ -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 diff --git a/testdata/del__dedupe__ok.ct b/testdata/del__dedupe__ok.ct index fe20f7a..f96873c 100644 --- a/testdata/del__dedupe__ok.ct +++ b/testdata/del__dedupe__ok.ct @@ -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 diff --git a/testdata/del__glob__mixed__ok.ct b/testdata/del__glob__mixed__ok.ct index 69a77fa..332a475 100644 --- a/testdata/del__glob__mixed__ok.ct +++ b/testdata/del__glob__mixed__ok.ct @@ -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 diff --git a/testdata/del__glob__ok.ct b/testdata/del__glob__ok.ct index c6cb99c..81fe095 100644 --- a/testdata/del__glob__ok.ct +++ b/testdata/del__glob__ok.ct @@ -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 diff --git a/testdata/del__multiple__ok.ct b/testdata/del__multiple__ok.ct index 80660d1..395e009 100644 --- a/testdata/del__multiple__ok.ct +++ b/testdata/del__multiple__ok.ct @@ -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 diff --git a/testdata/del__ok.ct b/testdata/del__ok.ct index 38d30cc..fa22746 100644 --- a/testdata/del__ok.ct +++ b/testdata/del__ok.ct @@ -1,2 +1,2 @@ $ pda set a b -$ pda del a +$ pda rm a diff --git a/testdata/help__del-db__ok.ct b/testdata/help__del-db__ok.ct index 1ab2233..0b7b0a8 100644 --- a/testdata/help__del-db__ok.ct +++ b/testdata/help__del-db__ok.ct @@ -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 diff --git a/testdata/help__del__ok.ct b/testdata/help__del__ok.ct index 9d53415..8556bc2 100644 --- a/testdata/help__del__ok.ct +++ b/testdata/help__del__ok.ct @@ -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 diff --git a/testdata/help__dump__ok.ct b/testdata/help__dump__ok.ct index 19cc6d8..380a94c 100644 --- a/testdata/help__dump__ok.ct +++ b/testdata/help__dump__ok.ct @@ -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 diff --git a/testdata/help__list-dbs__ok.ct b/testdata/help__list-dbs__ok.ct index 5f4a311..24ba6b5 100644 --- a/testdata/help__list-dbs__ok.ct +++ b/testdata/help__list-dbs__ok.ct @@ -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 diff --git a/testdata/help__ok.ct b/testdata/help__ok.ct index e14ce8e..339038a 100644 --- a/testdata/help__ok.ct +++ b/testdata/help__ok.ct @@ -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 diff --git a/testdata/help__restore__ok.ct b/testdata/help__restore__ok.ct index 3f1c4fb..b9fa6e5 100644 --- a/testdata/help__restore__ok.ct +++ b/testdata/help__restore__ok.ct @@ -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 diff --git a/testdata/restore__glob__ok.ct b/testdata/restore__glob__ok.ct index eefd176..3aa0b44 100644 --- a/testdata/restore__glob__ok.ct +++ b/testdata/restore__glob__ok.ct @@ -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 diff --git a/testdata/root__ok.ct b/testdata/root__ok.ct index 580ee43..f288cf9 100644 --- a/testdata/root__ok.ct +++ b/testdata/root__ok.ct @@ -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