Skip to content

Commit c6807fa

Browse files
committed
add link support
1 parent 9f1c5d9 commit c6807fa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/ctrlc/root/api/create/resources/resources.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package resources
22

33
import (
4+
"encoding/json"
45
"fmt"
56

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

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

47+
if len(links) > 0 {
48+
linksJSON, err := json.Marshal(links)
49+
if err != nil {
50+
return fmt.Errorf("failed to marshal links: %w", err)
51+
}
52+
metadata["ctrlplane/links"] = string(linksJSON)
53+
}
54+
4555
// Extrat into vars
4656
resp, err := client.UpsertTargets(cmd.Context(), api.UpsertTargetsJSONRequestBody{
4757
Targets: []struct {
@@ -86,6 +96,7 @@ func NewResourcesCmd() *cobra.Command {
8696
cmd.Flags().StringVar(&version, "version", "", "Version of the resource (required)")
8797
cmd.Flags().StringToStringVar(&metadata, "metadata", make(map[string]string), "Metadata key-value pairs (e.g. --metadata key=value)")
8898
cmd.Flags().StringToStringVar(&configArray, "config", make(map[string]string), "Config key-value pairs with nested values (can be specified multiple times)")
99+
cmd.Flags().StringToStringVar(&links, "link", make(map[string]string), "Links key-value pairs (can be specified multiple times)")
89100

90101
cmd.MarkFlagRequired("version")
91102
cmd.MarkFlagRequired("workspace")

0 commit comments

Comments
 (0)