Skip to content

Commit 88ddb25

Browse files
feat: regenerate CLI from OpenAPI spec
BREAKING CHANGE: regenerated from a breaking OpenAPI spec change
1 parent 68fcb1e commit 88ddb25

23 files changed

Lines changed: 902 additions & 157 deletions

‎client/client.gen.go‎

Lines changed: 542 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/hosting/hosting.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/hostinger/api-cli/cmd/hosting/nodejs"
99
"github.com/hostinger/api-cli/cmd/hosting/orders"
1010
"github.com/hostinger/api-cli/cmd/hosting/websites"
11-
"github.com/hostinger/api-cli/cmd/hosting/wordpress"
1211

1312
"github.com/spf13/cobra"
1413
)
@@ -26,5 +25,4 @@ func init() {
2625
GroupCmd.AddCommand(nodejs.GroupCmd)
2726
GroupCmd.AddCommand(orders.GroupCmd)
2827
GroupCmd.AddCommand(websites.GroupCmd)
29-
GroupCmd.AddCommand(wordpress.GroupCmd)
3028
}

‎cmd/root.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hostinger/api-cli/cmd/hosting"
1111
"github.com/hostinger/api-cli/cmd/reach"
1212
"github.com/hostinger/api-cli/cmd/vps"
13+
"github.com/hostinger/api-cli/cmd/wordpress"
1314
"os"
1415

1516
"github.com/hostinger/api-cli/utils"
@@ -59,6 +60,7 @@ func init() {
5960
RootCmd.AddCommand(hosting.GroupCmd)
6061
RootCmd.AddCommand(reach.GroupCmd)
6162
RootCmd.AddCommand(vps.GroupCmd)
63+
RootCmd.AddCommand(wordpress.GroupCmd)
6264
RootCmd.AddCommand(VersionCmd)
6365
}
6466

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wordpress
1+
package installations
22

33
import (
44
"bytes"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package wordpress
1+
package installations
22

33
import (
44
"github.com/spf13/cobra"
55
)
66

77
var GroupCmd = &cobra.Command{
8-
Use: "wordpress",
9-
Short: "Wordpress commands",
8+
Use: "installations",
9+
Short: "Installations commands",
1010
}
1111

1212
func init() {
1313
GroupCmd.AddCommand(InstallCmd)
14-
GroupCmd.AddCommand(ListInstallationsCmd)
14+
GroupCmd.AddCommand(ListCmd)
1515
}

cmd/hosting/wordpress/list_installations.go renamed to cmd/wordpress/installations/list.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wordpress
1+
package installations
22

33
import (
44
"context"
@@ -11,13 +11,13 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14-
var ListInstallationsCmd = &cobra.Command{
15-
Use: "list-installations",
14+
var ListCmd = &cobra.Command{
15+
Use: "list",
1616
Short: "List WordPress installations",
1717
Long: "List WordPress installations accessible to the authenticated client.\n\nUse this endpoint to discover existing WordPress installations and to poll\nfor installation status after calling the install endpoint. When a newly\nrequested installation appears in this list, WordPress is ready. Filter by\nusername and domain to narrow results to a specific website.\n\nEach installation includes a `valid` flag and, when invalid, a\n`validationError` describing why.",
1818
Run: func(cmd *cobra.Command, args []string) {
1919
utils.EnumCheck(cmd, "ownership", []string{"owned", "managed", "all"})
20-
r, err := api.Request().HostingListWordPressInstallationsV1WithResponse(context.TODO(), listInstallationsParams(cmd))
20+
r, err := api.Request().HostingListWordPressInstallationsV1WithResponse(context.TODO(), listParams(cmd))
2121
if err != nil {
2222
log.Fatal(err)
2323
}
@@ -27,12 +27,12 @@ var ListInstallationsCmd = &cobra.Command{
2727
}
2828

2929
func init() {
30-
ListInstallationsCmd.Flags().StringP("username", "", "", "Filter by specific username")
31-
ListInstallationsCmd.Flags().StringP("domain", "", "", "Filter by domain name (exact match)")
32-
ListInstallationsCmd.Flags().StringP("ownership", "", "", "Filter by ownership type. Defaults to \"owned\". Use \"all\" to include both owned and managed installations. (one of: owned, managed, all)")
30+
ListCmd.Flags().StringP("username", "", "", "Filter by specific username")
31+
ListCmd.Flags().StringP("domain", "", "", "Filter by domain name (exact match)")
32+
ListCmd.Flags().StringP("ownership", "", "", "Filter by ownership type. Defaults to \"owned\". Use \"all\" to include both owned and managed installations. (one of: owned, managed, all)")
3333
}
3434

35-
func listInstallationsParams(cmd *cobra.Command) *client.HostingListWordPressInstallationsV1Params {
35+
func listParams(cmd *cobra.Command) *client.HostingListWordPressInstallationsV1Params {
3636
params := &client.HostingListWordPressInstallationsV1Params{}
3737
if cmd.Flags().Changed("username") {
3838
v, _ := cmd.Flags().GetString("username")

‎cmd/wordpress/plugins/install.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package plugins
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 InstallCmd = &cobra.Command{
15+
Use: "install <username> <software>",
16+
Short: "Install WordPress plugins",
17+
Long: "Install one or more plugins on an existing WordPress installation.\n\nProvide the WordPress installation (software) identifier in the path. It can\nbe obtained from GET /api/hosting/v1/wordpress/installations (the `id`\nfield). Use GET /api/hosting/v1/wordpress/plugins to discover the plugin\nslugs available for installation.\n\nThis operation is asynchronous: a successful response only means the install\njob has been queued, not that the plugins are ready.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(installBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().HostingInstallWordPressPluginsV1WithBodyWithResponse(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+
InstallCmd.Flags().StringSliceP("plugins", "", nil, "Plugin slugs to install. Use GET /api/hosting/v1/wordpress/plugins to discover available slugs.")
35+
InstallCmd.MarkFlagRequired("plugins")
36+
}
37+
38+
func installBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
pluginsVal, _ := cmd.Flags().GetStringSlice("plugins")
41+
body["plugins"] = pluginsVal
42+
return body
43+
}

‎cmd/wordpress/plugins/plugins.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package plugins
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "plugins",
9+
Short: "Plugins commands",
10+
}
11+
12+
func init() {
13+
GroupCmd.AddCommand(InstallCmd)
14+
}

‎cmd/wordpress/themes/install.go‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package themes
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 InstallCmd = &cobra.Command{
16+
Use: "install <username> <software>",
17+
Short: "Install WordPress theme",
18+
Long: "Install a theme on an existing WordPress installation.\n\nProvide the WordPress installation (software) identifier in the path. It can\nbe obtained from GET /api/hosting/v1/wordpress/installations (the `id`\nfield).\n\nWhen the theme is one of the Hostinger themes (hostinger-blog,\nhostinger-affiliate-theme, hostinger-ai-theme), the optional `palette`,\n`layout`, and `font` fields are forwarded to the custom installer (defaults:\npalette1, layout1, default). For any other theme they are ignored.\n\nThis operation is asynchronous: a successful response only means the install\njob has been queued, not that the theme is ready.",
19+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
20+
Run: func(cmd *cobra.Command, args []string) {
21+
utils.EnumCheck(cmd, "font", []string{"professional", "modern", "elegant", "creative", "dynamic", "default"})
22+
payload, err := json.Marshal(installBody(cmd))
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
r, err := api.Request().HostingInstallWordPressThemeV1WithBodyWithResponse(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+
InstallCmd.Flags().StringP("font", "", "default", "Font identifier. Only applied when the theme is a Hostinger theme; the default is used when omitted. (one of: professional, modern, elegant, creative, dynamic, default)")
37+
InstallCmd.Flags().StringP("layout", "", "layout1", "Layout identifier. Only applied when the theme is a Hostinger theme; the default is used when omitted.")
38+
InstallCmd.Flags().StringP("palette", "", "palette1", "Palette identifier. Only applied when the theme is a Hostinger theme; the default is used when omitted.")
39+
InstallCmd.Flags().StringP("theme", "", "", "Slug of the theme to install. Hostinger theme slugs (hostinger-blog, hostinger-affiliate-theme, hostinger-ai-theme) trigger the custom installer and forward the optional palette/layout/font fields; any other WordPress theme slug uses the standard installer and ignores those fields.")
40+
InstallCmd.MarkFlagRequired("theme")
41+
}
42+
43+
func installBody(cmd *cobra.Command) map[string]any {
44+
body := map[string]any{}
45+
if cmd.Flags().Changed("font") {
46+
v, _ := cmd.Flags().GetString("font")
47+
body["font"] = v
48+
}
49+
if cmd.Flags().Changed("layout") {
50+
v, _ := cmd.Flags().GetString("layout")
51+
body["layout"] = v
52+
}
53+
if cmd.Flags().Changed("palette") {
54+
v, _ := cmd.Flags().GetString("palette")
55+
body["palette"] = v
56+
}
57+
themeVal, _ := cmd.Flags().GetString("theme")
58+
body["theme"] = themeVal
59+
return body
60+
}

‎cmd/wordpress/themes/themes.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package themes
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var GroupCmd = &cobra.Command{
8+
Use: "themes",
9+
Short: "Themes commands",
10+
}
11+
12+
func init() {
13+
GroupCmd.AddCommand(InstallCmd)
14+
}

0 commit comments

Comments
 (0)