Skip to content

Commit efefce9

Browse files
committed
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.
1 parent f493461 commit efefce9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

internal/service/resource_definition.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,23 @@ func ExecuteResourceCommand(r *api.Resource, args []string) (*http.Request, stri
4646
}
4747

4848
if r.CreateMethod != nil {
49+
use := "create [id]"
50+
args := cobra.ExactArgs(0)
51+
if !r.CreateMethod.SupportsUserSettableCreate {
52+
use = "create"
53+
args = cobra.ExactArgs(1)
54+
}
4955
createArgs := map[string]interface{}{}
5056
createCmd := &cobra.Command{
51-
Use: "create [id]",
57+
Use: use,
5258
Short: fmt.Sprintf("Create a %v", strings.ToLower(r.Singular)),
53-
Args: cobra.ExactArgs(1),
59+
Args: args,
5460
Run: func(cmd *cobra.Command, args []string) {
55-
id := args[0]
56-
p := withPrefix(fmt.Sprintf("?id=%s", id))
61+
p := withPrefix("")
62+
if r.CreateMethod.SupportsUserSettableCreate {
63+
id := args[0]
64+
p = withPrefix(fmt.Sprintf("?id=%s", id))
65+
}
5766
jsonBody, err := generateJsonPayload(cmd, createArgs)
5867
if err != nil {
5968
slog.Error(fmt.Sprintf("unable to create json body for update: %v", err))

0 commit comments

Comments
 (0)