From 3d0add35e37fc7d2cbe3c4ef9155391f478bddb5 Mon Sep 17 00:00:00 2001 From: jmug Date: Sat, 24 Oct 2026 02:28:54 -0700 Subject: [PATCH] feat: Subcommands for maps and array values. --- internal/clis/hmsecrets/get-arr.go | 26 +++++++++++++++++++++++ internal/clis/hmsecrets/get-map.go | 26 +++++++++++++++++++++++ internal/clis/hmsecrets/set-arr.go | 34 ++++++++++++++++++++++++++++++ internal/clis/hmsecrets/set-map.go | 34 ++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 internal/clis/hmsecrets/get-arr.go create mode 100644 internal/clis/hmsecrets/get-map.go create mode 100644 internal/clis/hmsecrets/set-arr.go create mode 100644 internal/clis/hmsecrets/set-map.go diff --git a/internal/clis/hmsecrets/get-arr.go b/internal/clis/hmsecrets/get-arr.go new file mode 100644 index 0000000..73863f4 --- /dev/null +++ b/internal/clis/hmsecrets/get-arr.go @@ -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 + }, +} diff --git a/internal/clis/hmsecrets/get-map.go b/internal/clis/hmsecrets/get-map.go new file mode 100644 index 0000000..72b2db3 --- /dev/null +++ b/internal/clis/hmsecrets/get-map.go @@ -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 + }, +} diff --git a/internal/clis/hmsecrets/set-arr.go b/internal/clis/hmsecrets/set-arr.go new file mode 100644 index 0000000..d2168aa --- /dev/null +++ b/internal/clis/hmsecrets/set-arr.go @@ -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 + }, +} diff --git a/internal/clis/hmsecrets/set-map.go b/internal/clis/hmsecrets/set-map.go new file mode 100644 index 0000000..bb25cbd --- /dev/null +++ b/internal/clis/hmsecrets/set-map.go @@ -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 + }, +}