Skip to content

Commit

Permalink
add link support
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Nov 13, 2024
1 parent 9f1c5d9 commit c6807fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/ctrlc/root/api/create/resources/resources.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resources

import (
"encoding/json"
"fmt"

"github.com/MakeNowJust/heredoc/v2"
Expand All @@ -19,6 +20,7 @@ func NewResourcesCmd() *cobra.Command {
var version string
var metadata map[string]string
var configArray map[string]string
var links map[string]string

cmd := &cobra.Command{
Use: "resources [flags]",
Expand All @@ -42,6 +44,14 @@ func NewResourcesCmd() *cobra.Command {
// Convert configArray into a nested map[string]interface{}
config := cliutil.ConvertConfigArrayToNestedMap(configArray)

if len(links) > 0 {
linksJSON, err := json.Marshal(links)
if err != nil {
return fmt.Errorf("failed to marshal links: %w", err)
}
metadata["ctrlplane/links"] = string(linksJSON)
}

// Extrat into vars
resp, err := client.UpsertTargets(cmd.Context(), api.UpsertTargetsJSONRequestBody{
Targets: []struct {
Expand Down Expand Up @@ -86,6 +96,7 @@ func NewResourcesCmd() *cobra.Command {
cmd.Flags().StringVar(&version, "version", "", "Version of the resource (required)")
cmd.Flags().StringToStringVar(&metadata, "metadata", make(map[string]string), "Metadata key-value pairs (e.g. --metadata key=value)")
cmd.Flags().StringToStringVar(&configArray, "config", make(map[string]string), "Config key-value pairs with nested values (can be specified multiple times)")
cmd.Flags().StringToStringVar(&links, "link", make(map[string]string), "Links key-value pairs (can be specified multiple times)")

cmd.MarkFlagRequired("version")
cmd.MarkFlagRequired("workspace")
Expand Down

0 comments on commit c6807fa

Please sign in to comment.