feat: Subcommands for maps and array values.

This commit is contained in:
jmug committed 2026-10-24 02:28:54 -07:00
1 parent f65e0c7eaa
commit 3d0add35e3
4 files changed
+120

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
package hmsecrets
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(getArrCmd)
}
var getArrCmd = &cobra.Command{
Use: "get-array",
Short: "get-array [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
secret, err := cli.GetStringArr(args[0])
if err != nil {
return err
}
fmt.Println(secret)
return nil
},
}
+26
View File
@@ -0,0 +1,26 @@
package hmsecrets
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(getMapCmd)
}
var getMapCmd = &cobra.Command{
Use: "get-map",
Short: "get-map [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
secret, err := cli.GetStringMap(args[0])
if err != nil {
return err
}
fmt.Println(secret)
return nil
},
}
+34
View File
@@ -0,0 +1,34 @@
package hmsecrets
import (
"github.com/spf13/cobra"
)
var arrValue []string
func init() {
rootCmd.AddCommand(setArrCmd)
setArrCmd.Flags().StringArrayVarP(
&arrValue,
"array-value",
"v",
nil,
"array value to store in the secret",
)
setArrCmd.MarkFlagRequired("array-value")
}
var setArrCmd = &cobra.Command{
Use: "set-array",
Short: "set-array [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
err := cli.PutStringArr(args[0], arrValue)
if err != nil {
return err
}
return nil
},
}
+34
View File
@@ -0,0 +1,34 @@
package hmsecrets
import (
"github.com/spf13/cobra"
)
var mapValue map[string]string
func init() {
rootCmd.AddCommand(setMapCmd)
setMapCmd.Flags().StringToStringVarP(
&mapValue,
"map-value",
"v",
nil,
"map value to store in the secret",
)
setArrCmd.MarkFlagRequired("map-value")
}
var setMapCmd = &cobra.Command{
Use: "set-map",
Short: "set-map [key]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cli := getClient(apiBase, caFile, clientCert, clientKey)
err := cli.PutStringMap(args[0], mapValue)
if err != nil {
return err
}
return nil
},
}