feat(completions): wire up store completions and --store flag completions

This commit is contained in:
Lewis Wynne 2026-03-16 16:31:37 +00:00
parent cb135b7caa
commit 84b1c67c72
6 changed files with 35 additions and 25 deletions

View file

@ -33,12 +33,13 @@ import (
// delStoreCmd represents the set command // delStoreCmd represents the set command
var delStoreCmd = &cobra.Command{ var delStoreCmd = &cobra.Command{
Use: "remove-store STORE", Use: "remove-store STORE",
Short: "Delete a store", Short: "Delete a store",
Aliases: []string{"rms"}, Aliases: []string{"rms"},
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: delStore, ValidArgsFunction: completeStores,
SilenceUsage: true, RunE: delStore,
SilenceUsage: true,
} }
func delStore(cmd *cobra.Command, args []string) error { func delStore(cmd *cobra.Command, args []string) error {

View file

@ -34,9 +34,10 @@ import (
var delCmd = &cobra.Command{ var delCmd = &cobra.Command{
Use: "remove KEY[@STORE] [KEY[@STORE] ...]", Use: "remove KEY[@STORE] [KEY[@STORE] ...]",
Short: "Delete one or more keys", Short: "Delete one or more keys",
Aliases: []string{"rm"}, Aliases: []string{"rm"},
Args: cobra.ArbitraryArgs, Args: cobra.ArbitraryArgs,
RunE: del, ValidArgsFunction: completeKeys,
RunE: del,
SilenceUsage: true, SilenceUsage: true,
} }
@ -145,6 +146,7 @@ func init() {
delCmd.Flags().Bool("force", false, "bypass read-only protection") delCmd.Flags().Bool("force", false, "bypass read-only protection")
delCmd.Flags().StringSliceP("key", "k", nil, "delete keys matching glob pattern (repeatable)") delCmd.Flags().StringSliceP("key", "k", nil, "delete keys matching glob pattern (repeatable)")
delCmd.Flags().StringSliceP("store", "s", nil, "target stores matching glob pattern (repeatable)") delCmd.Flags().StringSliceP("store", "s", nil, "target stores matching glob pattern (repeatable)")
delCmd.RegisterFlagCompletionFunc("store", completeStoreFlag)
delCmd.Flags().StringSliceP("value", "v", nil, "delete entries matching value glob pattern (repeatable)") delCmd.Flags().StringSliceP("value", "v", nil, "delete entries matching value glob pattern (repeatable)")
rootCmd.AddCommand(delCmd) rootCmd.AddCommand(delCmd)
} }

View file

@ -31,6 +31,7 @@ var exportCmd = &cobra.Command{
Short: "Export store as NDJSON (alias for list --format ndjson)", Short: "Export store as NDJSON (alias for list --format ndjson)",
Aliases: []string{}, Aliases: []string{},
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
ValidArgsFunction: completeStores,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
listFormat = "ndjson" listFormat = "ndjson"
return list(cmd, args) return list(cmd, args)
@ -41,6 +42,7 @@ var exportCmd = &cobra.Command{
func init() { func init() {
exportCmd.Flags().StringSliceP("key", "k", nil, "filter keys with glob pattern (repeatable)") exportCmd.Flags().StringSliceP("key", "k", nil, "filter keys with glob pattern (repeatable)")
exportCmd.Flags().StringSliceP("store", "s", nil, "filter stores with glob pattern (repeatable)") exportCmd.Flags().StringSliceP("store", "s", nil, "filter stores with glob pattern (repeatable)")
exportCmd.RegisterFlagCompletionFunc("store", completeStoreFlag)
exportCmd.Flags().StringSliceP("value", "v", nil, "filter values with glob pattern (repeatable)") exportCmd.Flags().StringSliceP("value", "v", nil, "filter values with glob pattern (repeatable)")
rootCmd.AddCommand(exportCmd) rootCmd.AddCommand(exportCmd)
} }

View file

@ -141,10 +141,11 @@ glob pattern to filter by store name.
Use --key/-k and --value/-v to filter by key or value glob, and --store/-s Use --key/-k and --value/-v to filter by key or value glob, and --store/-s
to filter by store name. All filters are repeatable and OR'd within the to filter by store name. All filters are repeatable and OR'd within the
same flag.`, same flag.`,
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
RunE: list, ValidArgsFunction: completeStores,
SilenceUsage: true, RunE: list,
SilenceUsage: true,
} }
func list(cmd *cobra.Command, args []string) error { func list(cmd *cobra.Command, args []string) error {
@ -785,6 +786,7 @@ func init() {
listCmd.Flags().VarP(&listFormat, "format", "o", "output format (table|tsv|csv|markdown|html|ndjson|json)") listCmd.Flags().VarP(&listFormat, "format", "o", "output format (table|tsv|csv|markdown|html|ndjson|json)")
listCmd.Flags().StringSliceP("key", "k", nil, "filter keys with glob pattern (repeatable)") listCmd.Flags().StringSliceP("key", "k", nil, "filter keys with glob pattern (repeatable)")
listCmd.Flags().StringSliceP("store", "s", nil, "filter stores with glob pattern (repeatable)") listCmd.Flags().StringSliceP("store", "s", nil, "filter stores with glob pattern (repeatable)")
listCmd.RegisterFlagCompletionFunc("store", completeStoreFlag)
listCmd.Flags().StringSliceP("value", "v", nil, "filter values with glob pattern (repeatable)") listCmd.Flags().StringSliceP("value", "v", nil, "filter values with glob pattern (repeatable)")
rootCmd.AddCommand(listCmd) rootCmd.AddCommand(listCmd)
} }

View file

@ -33,12 +33,13 @@ import (
// mvStoreCmd represents the move-store command // mvStoreCmd represents the move-store command
var mvStoreCmd = &cobra.Command{ var mvStoreCmd = &cobra.Command{
Use: "move-store FROM TO", Use: "move-store FROM TO",
Short: "Rename a store", Short: "Rename a store",
Aliases: []string{"mvs"}, Aliases: []string{"mvs"},
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
RunE: mvStore, ValidArgsFunction: completeStores,
SilenceUsage: true, RunE: mvStore,
SilenceUsage: true,
} }
func mvStore(cmd *cobra.Command, args []string) error { func mvStore(cmd *cobra.Command, args []string) error {

View file

@ -37,12 +37,13 @@ import (
) )
var restoreCmd = &cobra.Command{ var restoreCmd = &cobra.Command{
Use: "import [STORE]", Use: "import [STORE]",
Short: "Restore key/value pairs from an NDJSON dump", Short: "Restore key/value pairs from an NDJSON dump",
Aliases: []string{}, Aliases: []string{},
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
RunE: restore, ValidArgsFunction: completeStores,
SilenceUsage: true, RunE: restore,
SilenceUsage: true,
} }
func restore(cmd *cobra.Command, args []string) error { func restore(cmd *cobra.Command, args []string) error {
@ -323,6 +324,7 @@ func init() {
restoreCmd.Flags().StringP("file", "f", "", "path to an NDJSON dump (defaults to stdin)") restoreCmd.Flags().StringP("file", "f", "", "path to an NDJSON dump (defaults to stdin)")
restoreCmd.Flags().StringSliceP("key", "k", nil, "restore keys matching glob pattern (repeatable)") restoreCmd.Flags().StringSliceP("key", "k", nil, "restore keys matching glob pattern (repeatable)")
restoreCmd.Flags().StringSliceP("store", "s", nil, "restore entries from stores matching glob pattern (repeatable)") restoreCmd.Flags().StringSliceP("store", "s", nil, "restore entries from stores matching glob pattern (repeatable)")
restoreCmd.RegisterFlagCompletionFunc("store", completeStoreFlag)
restoreCmd.Flags().BoolP("interactive", "i", false, "prompt before overwriting existing keys") restoreCmd.Flags().BoolP("interactive", "i", false, "prompt before overwriting existing keys")
restoreCmd.Flags().Bool("drop", false, "drop existing entries before restoring (full replace)") restoreCmd.Flags().Bool("drop", false, "drop existing entries before restoring (full replace)")
rootCmd.AddCommand(restoreCmd) rootCmd.AddCommand(restoreCmd)