Skip to content

Commit b07487e

Browse files
chore: regenerate CLI from OpenAPI spec
1 parent a1d49f3 commit b07487e

18 files changed

Lines changed: 3235 additions & 793 deletions

‎client/client.gen.go‎

Lines changed: 2720 additions & 790 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package forms
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var AddSubmitterTagsCmd = &cobra.Command{
15+
Use: "add-submitter-tags <profile-uuid> <form-uuid>",
16+
Short: "Add form submitter tags",
17+
Long: "Add tags to a form so that every contact who submits it from now on receives them.\n\nA tag the form already has is skipped; an unknown tag is rejected. Contacts who submitted earlier are\nnot tagged.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(addSubmitterTagsBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().ReachAddFormSubmitterTagsV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
AddSubmitterTagsCmd.Flags().StringSliceP("tag-uuids", "", nil, "")
35+
AddSubmitterTagsCmd.MarkFlagRequired("tag-uuids")
36+
}
37+
38+
func addSubmitterTagsBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
tagUuidsVal, _ := cmd.Flags().GetStringSlice("tag-uuids")
41+
body["tag_uuids"] = tagUuidsVal
42+
return body
43+
}

‎cmd/reach/forms/create.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package forms
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var CreateCmd = &cobra.Command{
15+
Use: "create <profile-uuid>",
16+
Short: "Create form",
17+
Long: "Create an empty draft form.\n\nReach also adds an automatic `form:{name}` tag that every submitter receives. A draft has no design\nand is not reachable by visitors: save a design with the update form template operation, then take\nthe form live by setting its status to `active`. Creating a form does not consume AI credits.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(createBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().ReachCreateFormV1WithBodyWithResponse(context.TODO(), args[0], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
CreateCmd.Flags().StringP("name", "", "", "Form name. Letters, digits, spaces and - . ' _ only.")
35+
CreateCmd.MarkFlagRequired("name")
36+
}
37+
38+
func createBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
nameVal, _ := cmd.Flags().GetString("name")
41+
body["name"] = nameVal
42+
return body
43+
}

‎cmd/reach/forms/duplicate.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package forms
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/output"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var DuplicateCmd = &cobra.Command{
13+
Use: "duplicate <profile-uuid> <form-uuid>",
14+
Short: "Duplicate form",
15+
Long: "Copy a form into a new draft form with the same name and design.\n\nThe copy shares the source's automatic `form:{name}` tag; other submitter tags are not copied. The\ncopy is not live until its status is set to `active`.",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().ReachDuplicateFormV1WithResponse(context.TODO(), args[0], args[1])
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}

‎cmd/reach/forms/forms.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ var GroupCmd = &cobra.Command{
1010
}
1111

1212
func init() {
13+
GroupCmd.AddCommand(AddSubmitterTagsCmd)
14+
GroupCmd.AddCommand(CreateCmd)
1315
GroupCmd.AddCommand(DeleteCmd)
16+
GroupCmd.AddCommand(DuplicateCmd)
1417
GroupCmd.AddCommand(GetCmd)
1518
GroupCmd.AddCommand(ListCmd)
19+
GroupCmd.AddCommand(RemoveSubmitterTagCmd)
20+
GroupCmd.AddCommand(UpdateCmd)
21+
GroupCmd.AddCommand(UpdateTemplateCmd)
1622
}

‎cmd/reach/forms/list.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/hostinger/api-cli/api"
88
"github.com/hostinger/api-cli/client"
99
"github.com/hostinger/api-cli/output"
10+
"github.com/hostinger/api-cli/utils"
1011
"github.com/spf13/cobra"
1112
)
1213

@@ -16,6 +17,7 @@ var ListCmd = &cobra.Command{
1617
Long: "Get a paginated list of the signup forms in a profile.\n\nEach form carries a reference to the template that renders it. Get the form details for a\ndirectly usable template URL and for the tags the form puts on the contacts it captures.",
1718
Args: cobra.MatchAll(cobra.ExactArgs(1)),
1819
Run: func(cmd *cobra.Command, args []string) {
20+
utils.EnumCheck(cmd, "status", []string{"active", "paused", "draft"})
1921
r, err := api.Request().ReachListFormsV1WithResponse(context.TODO(), args[0], listParams(cmd))
2022
if err != nil {
2123
log.Fatal(err)
@@ -28,6 +30,7 @@ var ListCmd = &cobra.Command{
2830
func init() {
2931
ListCmd.Flags().IntP("page", "", 0, "Page number")
3032
ListCmd.Flags().IntP("per-page", "", 25, "Number of items per page")
33+
ListCmd.Flags().StringP("status", "", "", "Return only forms with this status. (one of: active, paused, draft)")
3134
}
3235

3336
func listParams(cmd *cobra.Command) *client.ReachListFormsV1Params {
@@ -40,5 +43,10 @@ func listParams(cmd *cobra.Command) *client.ReachListFormsV1Params {
4043
v, _ := cmd.Flags().GetInt("per-page")
4144
params.PerPage = &v
4245
}
46+
if cmd.Flags().Changed("status") {
47+
v, _ := cmd.Flags().GetString("status")
48+
e := client.ReachListFormsV1ParamsStatus(v)
49+
params.Status = &e
50+
}
4351
return params
4452
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package forms
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var RemoveSubmitterTagCmd = &cobra.Command{
15+
Use: "remove-submitter-tag <profile-uuid> <form-uuid>",
16+
Short: "Remove form submitter tag",
17+
Long: "Stop a form from applying a tag to its future submitters.\n\nSucceeds also when the form did not have the tag. Contacts who already received the tag keep it, and\nthe tag itself is not deleted. The automatic `form:{name}` tag cannot be removed and is rejected with\na conflict.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(removeSubmitterTagBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().ReachRemoveFormSubmitterTagV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
RemoveSubmitterTagCmd.Flags().StringP("tag-uuid", "", "", "")
35+
RemoveSubmitterTagCmd.MarkFlagRequired("tag-uuid")
36+
}
37+
38+
func removeSubmitterTagBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
tagUuidVal, _ := cmd.Flags().GetString("tag-uuid")
41+
body["tag_uuid"] = tagUuidVal
42+
return body
43+
}

‎cmd/reach/forms/update.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package forms
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/hostinger/api-cli/utils"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var UpdateCmd = &cobra.Command{
16+
Use: "update <profile-uuid> <form-uuid>",
17+
Short: "Update form",
18+
Long: "Rename a form and/or change its status.\n\nSetting a `draft` or `paused` form to `active` takes it live: its latest saved design is published\nand visitors can submit it. `paused` and `draft` stop the form from accepting submissions. A form is\nnot reachable by visitors until it is taken live. Design changes saved while the form is already\n`active` stay unpublished until the form is paused and set to `active` again. Renaming does not rename\nthe automatic `form:{name}` tag.",
19+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
20+
Run: func(cmd *cobra.Command, args []string) {
21+
utils.EnumCheck(cmd, "status", []string{"active", "paused", "draft"})
22+
payload, err := json.Marshal(updateBody(cmd))
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
r, err := api.Request().ReachUpdateFormV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
31+
output.Format(cmd, r.Body, r.StatusCode())
32+
},
33+
}
34+
35+
func init() {
36+
UpdateCmd.Flags().StringP("name", "", "", "Form name. Letters, digits, spaces and - . ' _ only.")
37+
UpdateCmd.Flags().StringP("status", "", "", "`active` takes the form live, `paused` and `draft` stop it accepting submissions. (one of: active, paused, draft)")
38+
}
39+
40+
func updateBody(cmd *cobra.Command) map[string]any {
41+
body := map[string]any{}
42+
if cmd.Flags().Changed("name") {
43+
v, _ := cmd.Flags().GetString("name")
44+
body["name"] = v
45+
}
46+
if cmd.Flags().Changed("status") {
47+
v, _ := cmd.Flags().GetString("status")
48+
body["status"] = v
49+
}
50+
return body
51+
}

‎cmd/reach/forms/update_template.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package forms
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"log"
8+
9+
"github.com/hostinger/api-cli/api"
10+
"github.com/hostinger/api-cli/output"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var UpdateTemplateCmd = &cobra.Command{
15+
Use: "update-template <profile-uuid> <form-uuid>",
16+
Short: "Update form template",
17+
Long: "Save `content` as the latest design of a form and return the stored version.\n\nThe HTML is sanitized and, unless the plan allows removing it, the Reach signature is added. Visitors\nsubmit the form with an `email` field (required) and optional `name`, `surname` and `phone`. After\nsanitizing, the design must contain a form container (`data-reach-form`), an email input\n(`data-reach-field=\"email\"`) and a submit button (`data-reach-submit`); otherwise the request fails\nwith `422` and `errors.content` lists `missing_form_container`, `missing_email_field` and/or\n`missing_submit_button`.\n\nA `draft` or `paused` form stays unreachable until its status is set to `active`, which publishes this\ndesign. On a form that is already `active` the saved design is not public until the form is paused and\nset to `active` again. Saving a design does not consume AI credits.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(updateTemplateBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().ReachUpdateFormTemplateV1WithBodyWithResponse(context.TODO(), args[0], args[1], "application/json", bytes.NewReader(payload))
25+
if err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
output.Format(cmd, r.Body, r.StatusCode())
30+
},
31+
}
32+
33+
func init() {
34+
UpdateTemplateCmd.Flags().StringP("content", "", "", "HTML of the form design. After sanitizing it must still contain a form container\n(`data-reach-form`), an email input (`data-reach-field=\"email\"`) and a submit button\n(`data-reach-submit`).")
35+
UpdateTemplateCmd.MarkFlagRequired("content")
36+
}
37+
38+
func updateTemplateBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
contentVal, _ := cmd.Flags().GetString("content")
41+
body["content"] = contentVal
42+
return body
43+
}

‎docs/hostinger_reach_forms.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ Forms commands
1818
### SEE ALSO
1919

2020
* [hostinger reach](hostinger_reach.md) - Reach commands
21+
* [hostinger reach forms add-submitter-tags](hostinger_reach_forms_add-submitter-tags.md) - Add form submitter tags
22+
* [hostinger reach forms create](hostinger_reach_forms_create.md) - Create form
2123
* [hostinger reach forms delete](hostinger_reach_forms_delete.md) - Delete form
24+
* [hostinger reach forms duplicate](hostinger_reach_forms_duplicate.md) - Duplicate form
2225
* [hostinger reach forms get](hostinger_reach_forms_get.md) - Get form details
2326
* [hostinger reach forms list](hostinger_reach_forms_list.md) - List forms
27+
* [hostinger reach forms remove-submitter-tag](hostinger_reach_forms_remove-submitter-tag.md) - Remove form submitter tag
28+
* [hostinger reach forms update](hostinger_reach_forms_update.md) - Update form
29+
* [hostinger reach forms update-template](hostinger_reach_forms_update-template.md) - Update form template
2430

0 commit comments

Comments
 (0)