From efefce99eb9e29943a3019bb3f9647f92087e310 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Tue, 12 Nov 2024 21:45:50 -0800 Subject: [PATCH] feat: adding support for non-user-settable ids some APIs do not support user-settable IDs, so it would be a bug to require them. --- internal/service/resource_definition.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/service/resource_definition.go b/internal/service/resource_definition.go index cdbd2aa..96c26fd 100644 --- a/internal/service/resource_definition.go +++ b/internal/service/resource_definition.go @@ -46,14 +46,23 @@ func ExecuteResourceCommand(r *api.Resource, args []string) (*http.Request, stri } if r.CreateMethod != nil { + use := "create [id]" + args := cobra.ExactArgs(0) + if !r.CreateMethod.SupportsUserSettableCreate { + use = "create" + args = cobra.ExactArgs(1) + } createArgs := map[string]interface{}{} createCmd := &cobra.Command{ - Use: "create [id]", + Use: use, Short: fmt.Sprintf("Create a %v", strings.ToLower(r.Singular)), - Args: cobra.ExactArgs(1), + Args: args, Run: func(cmd *cobra.Command, args []string) { - id := args[0] - p := withPrefix(fmt.Sprintf("?id=%s", id)) + p := withPrefix("") + if r.CreateMethod.SupportsUserSettableCreate { + id := args[0] + p = withPrefix(fmt.Sprintf("?id=%s", id)) + } jsonBody, err := generateJsonPayload(cmd, createArgs) if err != nil { slog.Error(fmt.Sprintf("unable to create json body for update: %v", err))