Skip to content

Commit 809aa0d

Browse files
feat: regenerate CLI from OpenAPI spec
1 parent 88ddb25 commit 809aa0d

36 files changed

Lines changed: 8584 additions & 4379 deletions

client/client.gen.go

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

cmd/wordpress/plugins/activate.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 ActivateCmd = &cobra.Command{
15+
Use: "activate <username> <software>",
16+
Short: "Activate WordPress plugin",
17+
Long: "Activate an installed plugin on a 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` field).\n\nThis operation is asynchronous: a successful response only means the activation\njob has been queued.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(activateBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().HostingActivateWordPressPluginV1WithBodyWithResponse(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+
ActivateCmd.Flags().StringP("plugin", "", "", "Slug of the installed plugin to activate.")
35+
ActivateCmd.MarkFlagRequired("plugin")
36+
}
37+
38+
func activateBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
pluginVal, _ := cmd.Flags().GetString("plugin")
41+
body["plugin"] = pluginVal
42+
return body
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package plugins
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var CheckIfWooCommerceIsInstalledCmd = &cobra.Command{
14+
Use: "check-if-woo-commerce-is-installed",
15+
Short: "Check if WooCommerce is installed",
16+
Long: "Check whether WooCommerce is installed on any WordPress installation of a\ndomain. Optionally filter by domain to scope the check.",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingCheckIfWooCommerceIsInstalledV1WithResponse(context.TODO(), checkIfWooCommerceIsInstalledParams(cmd))
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}
26+
27+
func init() {
28+
CheckIfWooCommerceIsInstalledCmd.Flags().StringP("domain", "", "", "Filter by domain name (exact match)")
29+
}
30+
31+
func checkIfWooCommerceIsInstalledParams(cmd *cobra.Command) *client.HostingCheckIfWooCommerceIsInstalledV1Params {
32+
params := &client.HostingCheckIfWooCommerceIsInstalledV1Params{}
33+
if cmd.Flags().Changed("domain") {
34+
v, _ := cmd.Flags().GetString("domain")
35+
params.Domain = &v
36+
}
37+
return params
38+
}
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 DeactivateCmd = &cobra.Command{
15+
Use: "deactivate <username> <software>",
16+
Short: "Deactivate WordPress plugin",
17+
Long: "Deactivate an installed plugin on a 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` field).\n\nThis operation is asynchronous: a successful response only means the\ndeactivation job has been queued.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(deactivateBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().HostingDeactivateWordPressPluginV1WithBodyWithResponse(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+
DeactivateCmd.Flags().StringP("plugin", "", "", "Slug of the installed plugin to deactivate.")
35+
DeactivateCmd.MarkFlagRequired("plugin")
36+
}
37+
38+
func deactivateBody(cmd *cobra.Command) map[string]any {
39+
body := map[string]any{}
40+
pluginVal, _ := cmd.Flags().GetString("plugin")
41+
body["plugin"] = pluginVal
42+
return body
43+
}

cmd/wordpress/plugins/list.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package plugins
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 ListCmd = &cobra.Command{
13+
Use: "list <username> <software>",
14+
Short: "List available WordPress plugins",
15+
Long: "List plugins recommended for installation on a WordPress installation that are\nnot yet installed.\n\nProvide the WordPress installation (software) identifier in the path. It can\nbe obtained from GET /api/hosting/v1/wordpress/installations (the `id` field).",
16+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingListAvailableWordPressPluginsV1WithResponse(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+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package plugins
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/hostinger/api-cli/utils"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var ListInstalledCmd = &cobra.Command{
15+
Use: "list-installed <username> <software>",
16+
Short: "List installed WordPress plugins",
17+
Long: "List plugins installed on a WordPress installation, including their status,\navailable updates and known vulnerabilities.\n\nProvide the WordPress installation (software) identifier in the path. It can\nbe obtained from GET /api/hosting/v1/wordpress/installations (the `id` field).",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
utils.EnumCheck(cmd, "category", []string{"cache"})
21+
r, err := api.Request().HostingListInstalledWordPressPluginsV1WithResponse(context.TODO(), args[0], args[1], listInstalledParams(cmd))
22+
if err != nil {
23+
log.Fatal(err)
24+
}
25+
26+
output.Format(cmd, r.Body, r.StatusCode())
27+
},
28+
}
29+
30+
func init() {
31+
ListInstalledCmd.Flags().StringP("category", "", "", "Filter installed plugins by category. (one of: cache)")
32+
}
33+
34+
func listInstalledParams(cmd *cobra.Command) *client.HostingListInstalledWordPressPluginsV1Params {
35+
params := &client.HostingListInstalledWordPressPluginsV1Params{}
36+
if cmd.Flags().Changed("category") {
37+
v, _ := cmd.Flags().GetString("category")
38+
e := client.HostingListInstalledWordPressPluginsV1ParamsCategory(v)
39+
params.Category = &e
40+
}
41+
return params
42+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package plugins
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var ListSuggestedCmd = &cobra.Command{
14+
Use: "list-suggested",
15+
Short: "List suggested WordPress plugins",
16+
Long: "List curated plugin suggestions grouped by website type.\n\nUse the returned `slug` values with\nPOST /api/hosting/v1/accounts/{username}/wordpress/{software}/plugins/install.",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingListSuggestedWordPressPluginsV1WithResponse(context.TODO(), listSuggestedParams(cmd))
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}
26+
27+
func init() {
28+
ListSuggestedCmd.Flags().IntP("order-id", "", 0, "Optionally scope suggestions to a specific order.")
29+
}
30+
31+
func listSuggestedParams(cmd *cobra.Command) *client.HostingListSuggestedWordPressPluginsV1Params {
32+
params := &client.HostingListSuggestedWordPressPluginsV1Params{}
33+
if cmd.Flags().Changed("order-id") {
34+
v, _ := cmd.Flags().GetInt("order-id")
35+
params.OrderId = &v
36+
}
37+
return params
38+
}

cmd/wordpress/plugins/plugins.go

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

1212
func init() {
13+
GroupCmd.AddCommand(ActivateCmd)
14+
GroupCmd.AddCommand(CheckIfWooCommerceIsInstalledCmd)
15+
GroupCmd.AddCommand(DeactivateCmd)
1316
GroupCmd.AddCommand(InstallCmd)
17+
GroupCmd.AddCommand(ListCmd)
18+
GroupCmd.AddCommand(ListInstalledCmd)
19+
GroupCmd.AddCommand(ListSuggestedCmd)
20+
GroupCmd.AddCommand(SearchCmd)
21+
GroupCmd.AddCommand(UninstallCmd)
22+
GroupCmd.AddCommand(UpdateCmd)
23+
GroupCmd.AddCommand(UpdateHostingerCmd)
1424
}

cmd/wordpress/plugins/search.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package plugins
2+
3+
import (
4+
"context"
5+
"log"
6+
7+
"github.com/hostinger/api-cli/api"
8+
"github.com/hostinger/api-cli/client"
9+
"github.com/hostinger/api-cli/output"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var SearchCmd = &cobra.Command{
14+
Use: "search",
15+
Short: "Search WordPress plugins",
16+
Long: "Search the WordPress.org plugin directory for plugins available to install.\n\nUse the returned `slug` values with\nPOST /api/hosting/v1/accounts/{username}/wordpress/{software}/plugins/install.",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
r, err := api.Request().HostingSearchWordPressPluginsV1WithResponse(context.TODO(), searchParams(cmd))
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
output.Format(cmd, r.Body, r.StatusCode())
24+
},
25+
}
26+
27+
func init() {
28+
SearchCmd.Flags().StringP("search", "", "", "Search term to match against plugin names. Minimum 3 characters.")
29+
SearchCmd.MarkFlagRequired("search")
30+
}
31+
32+
func searchParams(cmd *cobra.Command) *client.HostingSearchWordPressPluginsV1Params {
33+
params := &client.HostingSearchWordPressPluginsV1Params{}
34+
searchVal, _ := cmd.Flags().GetString("search")
35+
params.Search = searchVal
36+
return params
37+
}

cmd/wordpress/plugins/uninstall.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 UninstallCmd = &cobra.Command{
15+
Use: "uninstall <username> <software>",
16+
Short: "Uninstall WordPress plugins",
17+
Long: "Uninstall one or more plugins from a 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` field).\n\nThis operation is asynchronous: a successful response only means the uninstall\njob has been queued.",
18+
Args: cobra.MatchAll(cobra.ExactArgs(2)),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
payload, err := json.Marshal(uninstallBody(cmd))
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
r, err := api.Request().HostingUninstallWordPressPluginsV1WithBodyWithResponse(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+
UninstallCmd.Flags().StringSliceP("plugins", "", nil, "Slugs of the installed plugins to uninstall.")
35+
UninstallCmd.MarkFlagRequired("plugins")
36+
}
37+
38+
func uninstallBody(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+
}

0 commit comments

Comments
 (0)