mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
+ Add controller interface + Add renderable interface - A controller define his store. And Running cycle returning a renderable interface - Json is handle between Run & Render is the proper flag is set
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package regions
|
|
|
|
import (
|
|
fctl "github.com/formancehq/fctl/pkg"
|
|
"github.com/pterm/pterm"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type DeleteStore struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
type DeleteController struct {
|
|
store *DeleteStore
|
|
}
|
|
|
|
var _ fctl.Controller[*DeleteStore] = (*DeleteController)(nil)
|
|
|
|
func NewDefaultDeleteStore() *DeleteStore {
|
|
return &DeleteStore{}
|
|
}
|
|
|
|
func NewDeleteController() *DeleteController {
|
|
return &DeleteController{
|
|
store: NewDefaultDeleteStore(),
|
|
}
|
|
}
|
|
|
|
func NewDeleteCommand() *cobra.Command {
|
|
return fctl.NewCommand("delete <region-id>",
|
|
fctl.WithAliases("del", "d"),
|
|
fctl.WithShortDescription("Delete a private region"),
|
|
fctl.WithArgs(cobra.ExactArgs(1)),
|
|
fctl.WithController[*DeleteStore](NewDeleteController()),
|
|
)
|
|
}
|
|
|
|
func (c *DeleteController) GetStore() *DeleteStore {
|
|
return c.store
|
|
}
|
|
|
|
func (c *DeleteController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
|
|
|
|
cfg, err := fctl.GetConfig(cmd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
apiClient, err := fctl.NewMembershipClient(cmd, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
organizationID, err := fctl.ResolveOrganizationID(cmd, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = apiClient.DefaultApi.DeleteRegion(cmd.Context(), organizationID, args[0]).Execute()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
c.store.Success = true
|
|
|
|
return c, nil
|
|
}
|
|
|
|
func (c *DeleteController) Render(cmd *cobra.Command, args []string) error {
|
|
pterm.Success.WithWriter(cmd.OutOrStdout()).Printfln("Region deleted successfully!")
|
|
|
|
return nil
|
|
|
|
}
|