Skip to content

Commit

Permalink
feat: adding support for non-user-settable ids
Browse files Browse the repository at this point in the history
some APIs do not support user-settable IDs, so
it would be a bug to require them.
  • Loading branch information
toumorokoshi committed Nov 13, 2024
1 parent f493461 commit efefce9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/service/resource_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit efefce9

Please sign in to comment.