|
| 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 | +} |
0 commit comments