package hmsecrets import ( "encoding/json" "fmt" "os" "github.com/spf13/cobra" ) var mapValue map[string]string var mapFile string func init() { rootCmd.AddCommand(setMapCmd) setMapCmd.Flags().StringToStringVarP( &mapValue, "value", "v", nil, "map value to store in the secret", ) setMapCmd.Flags().StringVarP( &mapFile, "value-file", "f", "", "file that contains the secret value (in json) to set", ) setMapCmd.MarkFlagsOneRequired("value-file", "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() if mapFile != "" { mapJSONBytes, err := os.ReadFile(mapFile) if err != nil { return fmt.Errorf("reading map value file: %w", err) } err = json.Unmarshal(mapJSONBytes, &mapValue) if err != nil { return fmt.Errorf("reading value from map file: %w", err) } } err := cli.PutStringMap(args[0], mapValue) if err != nil { return err } return nil }, }