feat(completions): wire up store completions and --store flag completions
This commit is contained in:
parent
cb135b7caa
commit
84b1c67c72
6 changed files with 35 additions and 25 deletions
|
|
@ -33,12 +33,13 @@ import (
|
|||
|
||||
// delStoreCmd represents the set command
|
||||
var delStoreCmd = &cobra.Command{
|
||||
Use: "remove-store STORE",
|
||||
Short: "Delete a store",
|
||||
Aliases: []string{"rms"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: delStore,
|
||||
SilenceUsage: true,
|
||||
Use: "remove-store STORE",
|
||||
Short: "Delete a store",
|
||||
Aliases: []string{"rms"},
|
||||
Args: cobra.ExactArgs(1),
|
||||
ValidArgsFunction: completeStores,
|
||||
RunE: delStore,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
func delStore(cmd *cobra.Command, args []string) error {
|
||||
|
|
|
|||
|
|
@ -34,9 +34,10 @@ import (
|
|||
var delCmd = &cobra.Command{
|
||||
Use: "remove KEY[@STORE] [KEY[@STORE] ...]",
|
||||
Short: "Delete one or more keys",
|
||||
Aliases: []string{"rm"},
|
||||
Args: cobra.ArbitraryArgs,
|
||||
RunE: del,
|
||||
Aliases: []string{"rm"},
|
||||
Args: cobra.ArbitraryArgs,
|
||||
ValidArgsFunction: completeKeys,
|
||||
RunE: del,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +146,7 @@ func init() {
|
|||
delCmd.Flags().Bool("force", false, "bypass read-only protection")
|
||||
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.RegisterFlagCompletionFunc("store", completeStoreFlag)
|
||||
delCmd.Flags().StringSliceP("value", "v", nil, "delete entries matching value glob pattern (repeatable)")
|
||||
rootCmd.AddCommand(delCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ var exportCmd = &cobra.Command{
|
|||
Short: "Export store as NDJSON (alias for list --format ndjson)",
|
||||
Aliases: []string{},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ValidArgsFunction: completeStores,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
listFormat = "ndjson"
|
||||
return list(cmd, args)
|
||||
|
|
@ -41,6 +42,7 @@ var exportCmd = &cobra.Command{
|
|||
func init() {
|
||||
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.RegisterFlagCompletionFunc("store", completeStoreFlag)
|
||||
exportCmd.Flags().StringSliceP("value", "v", nil, "filter values with glob pattern (repeatable)")
|
||||
rootCmd.AddCommand(exportCmd)
|
||||
}
|
||||
|
|
|
|||
10
cmd/list.go
10
cmd/list.go
|
|
@ -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
|
||||
to filter by store name. All filters are repeatable and OR'd within the
|
||||
same flag.`,
|
||||
Aliases: []string{"ls"},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: list,
|
||||
SilenceUsage: true,
|
||||
Aliases: []string{"ls"},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ValidArgsFunction: completeStores,
|
||||
RunE: list,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
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().StringSliceP("key", "k", nil, "filter keys 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)")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
13
cmd/mv-db.go
13
cmd/mv-db.go
|
|
@ -33,12 +33,13 @@ import (
|
|||
|
||||
// mvStoreCmd represents the move-store command
|
||||
var mvStoreCmd = &cobra.Command{
|
||||
Use: "move-store FROM TO",
|
||||
Short: "Rename a store",
|
||||
Aliases: []string{"mvs"},
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: mvStore,
|
||||
SilenceUsage: true,
|
||||
Use: "move-store FROM TO",
|
||||
Short: "Rename a store",
|
||||
Aliases: []string{"mvs"},
|
||||
Args: cobra.ExactArgs(2),
|
||||
ValidArgsFunction: completeStores,
|
||||
RunE: mvStore,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
func mvStore(cmd *cobra.Command, args []string) error {
|
||||
|
|
|
|||
|
|
@ -37,12 +37,13 @@ import (
|
|||
)
|
||||
|
||||
var restoreCmd = &cobra.Command{
|
||||
Use: "import [STORE]",
|
||||
Short: "Restore key/value pairs from an NDJSON dump",
|
||||
Aliases: []string{},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: restore,
|
||||
SilenceUsage: true,
|
||||
Use: "import [STORE]",
|
||||
Short: "Restore key/value pairs from an NDJSON dump",
|
||||
Aliases: []string{},
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
ValidArgsFunction: completeStores,
|
||||
RunE: restore,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
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().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.RegisterFlagCompletionFunc("store", completeStoreFlag)
|
||||
restoreCmd.Flags().BoolP("interactive", "i", false, "prompt before overwriting existing keys")
|
||||
restoreCmd.Flags().Bool("drop", false, "drop existing entries before restoring (full replace)")
|
||||
rootCmd.AddCommand(restoreCmd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue