From bc0b98c7f925509f22000fd141cd9bd685988fd3 Mon Sep 17 00:00:00 2001 From: lew Date: Mon, 16 Mar 2026 16:31:57 +0000 Subject: [PATCH] feat(completions): wire up key completions for key commands --- cmd/edit.go | 7 ++++--- cmd/get.go | 12 +++++++----- cmd/meta.go | 5 +++-- cmd/mv.go | 26 ++++++++++++++------------ cmd/set.go | 7 ++++--- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cmd/edit.go b/cmd/edit.go index 96c31ad..a5cbe03 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -22,9 +22,10 @@ Binary values are presented as base64 for editing and decoded back on save. Metadata flags (--ttl, --encrypt, --decrypt) can be passed alongside the edit to modify metadata in the same operation.`, - Aliases: []string{"e"}, - Args: cobra.ExactArgs(1), - RunE: edit, + Aliases: []string{"e"}, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completeKeys, + RunE: edit, SilenceUsage: true, } diff --git a/cmd/get.go b/cmd/get.go index ff1f5a8..d4d9116 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -46,9 +46,10 @@ additional argument after the initial KEY being fetched. For example: pda set greeting 'Hello, {{ .NAME }}!' pda get greeting NAME=World`, - Aliases: []string{"g"}, - Args: cobra.MinimumNArgs(1), - RunE: get, + Aliases: []string{"g"}, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completeKeys, + RunE: get, SilenceUsage: true, } @@ -63,8 +64,9 @@ additional argument after the initial KEY being fetched. For example: pda set greeting 'Hello, {{ .NAME }}!' pda run greeting NAME=World`, - Args: cobra.MinimumNArgs(1), - RunE: run, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completeKeys, + RunE: run, SilenceUsage: true, } diff --git a/cmd/meta.go b/cmd/meta.go index 62b862a..91efc26 100644 --- a/cmd/meta.go +++ b/cmd/meta.go @@ -14,8 +14,9 @@ var metaCmd = &cobra.Command{ without changing its value. With no flags, displays the key's current metadata. Pass flags to modify.`, - Args: cobra.ExactArgs(1), - RunE: meta, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completeKeys, + RunE: meta, SilenceUsage: true, } diff --git a/cmd/mv.go b/cmd/mv.go index fa7b9d4..1594962 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -30,21 +30,23 @@ import ( ) var cpCmd = &cobra.Command{ - Use: "copy FROM[@STORE] TO[@STORE]", - Aliases: []string{"cp"}, - Short: "Make a copy of a key", - Args: cobra.ExactArgs(2), - RunE: cp, - SilenceUsage: true, + Use: "copy FROM[@STORE] TO[@STORE]", + Aliases: []string{"cp"}, + Short: "Make a copy of a key", + Args: cobra.ExactArgs(2), + ValidArgsFunction: completeKeys, + RunE: cp, + SilenceUsage: true, } var mvCmd = &cobra.Command{ - Use: "move FROM[@STORE] TO[@STORE]", - Aliases: []string{"mv"}, - Short: "Move a key", - Args: cobra.ExactArgs(2), - RunE: mv, - SilenceUsage: true, + Use: "move FROM[@STORE] TO[@STORE]", + Aliases: []string{"mv"}, + Short: "Move a key", + Args: cobra.ExactArgs(2), + ValidArgsFunction: completeKeys, + RunE: mv, + SilenceUsage: true, } func cp(cmd *cobra.Command, args []string) error { diff --git a/cmd/set.go b/cmd/set.go index d81f41b..9435c94 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -50,9 +50,10 @@ For example: 'Hello, {{ default "World" .NAME }}' will default to World if NAME is blank. 'Hello, {{ require .NAME }}' will error if NAME is blank. '{{ enum .NAME "Alice" "Bob" }}' allows only NAME=Alice or NAME=Bob.`, - Aliases: []string{"s"}, - Args: cobra.RangeArgs(1, 2), - RunE: set, + Aliases: []string{"s"}, + Args: cobra.RangeArgs(1, 2), + ValidArgsFunction: completeKeys, + RunE: set, SilenceUsage: true, }