Skip to content

Commit 22307a7

Browse files
feat: regenerate CLI from OpenAPI spec
1 parent 715e194 commit 22307a7

6 files changed

Lines changed: 292 additions & 0 deletions

File tree

client/client.gen.go

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package mailboxes
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 CreateMailboxCmd = &cobra.Command{
15+
Use: "create-mailbox <order-id>",
16+
Short: "Create mailbox",
17+
Long: "Create a mailbox under the given mail order. The full email address is\ncomposed from the given local part and the domain of the order.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(1)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(createMailboxBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().MailCreateMailboxV1WithBodyWithResponse(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+
CreateMailboxCmd.Flags().StringP("local-part", "", "", "Local part of the mailbox address (the part before the @). The domain is taken from the order. Must start and end with a letter or digit; single dots, underscores and hyphens are allowed in between.")
35+
CreateMailboxCmd.Flags().StringP("password", "", "", "Mailbox password. Minimum 8 characters with uppercase, lowercase, number and special character.")
36+
CreateMailboxCmd.MarkFlagRequired("local-part")
37+
CreateMailboxCmd.MarkFlagRequired("password")
38+
}
39+
40+
func createMailboxBody(cmd *cobra.Command) map[string]any {
41+
body := map[string]any{}
42+
localPartVal, _ := cmd.Flags().GetString("local-part")
43+
body["local_part"] = localPartVal
44+
passwordVal, _ := cmd.Flags().GetString("password")
45+
body["password"] = passwordVal
46+
return body
47+
}

cmd/mail/mailboxes/mailboxes.go

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

1212
func init() {
13+
GroupCmd.AddCommand(CreateMailboxCmd)
1314
GroupCmd.AddCommand(MailboxCmd)
1415
}

docs/hostinger_mail_mailboxes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ Mailboxes commands
1818
### SEE ALSO
1919

2020
* [hostinger mail](hostinger_mail.md) - Mail commands
21+
* [hostinger mail mailboxes create-mailbox](hostinger_mail_mailboxes_create-mailbox.md) - Create mailbox
2122
* [hostinger mail mailboxes mailbox](hostinger_mail_mailboxes_mailbox.md) - Get mailbox list
2223

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## hostinger mail mailboxes create-mailbox
2+
3+
Create mailbox
4+
5+
### Synopsis
6+
7+
Create a mailbox under the given mail order. The full email address is
8+
composed from the given local part and the domain of the order.
9+
10+
```
11+
hostinger mail mailboxes create-mailbox <order-id> [flags]
12+
```
13+
14+
### Options
15+
16+
```
17+
-h, --help help for create-mailbox
18+
--local-part string Local part of the mailbox address (the part before the @). The domain is taken from the order. Must start and end with a letter or digit; single dots, underscores and hyphens are allowed in between.
19+
--password string Mailbox password. Minimum 8 characters with uppercase, lowercase, number and special character.
20+
```
21+
22+
### Options inherited from parent commands
23+
24+
```
25+
--config string Config file (default is $HOME/.hostinger.yaml)
26+
--format string Output format type (json|table|tree), default: table
27+
```
28+
29+
### SEE ALSO
30+
31+
* [hostinger mail mailboxes](hostinger_mail_mailboxes.md) - Mailboxes commands
32+

manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,11 @@
10541054
"method": "POST",
10551055
"path": "/api/hosting/v1/domains/verify-ownership"
10561056
},
1057+
"mail_createMailboxV1": {
1058+
"command": "hostinger mail mailboxes create-mailbox",
1059+
"method": "POST",
1060+
"path": "/api/mail/v1/orders/{orderId}/mailboxes"
1061+
},
10571062
"mail_getMailOrderListV1": {
10581063
"command": "hostinger mail orders list",
10591064
"method": "GET",

0 commit comments

Comments
 (0)