Files
2024-03-15 15:16:03 +00:00

66 lines
1.4 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) {
store := fctl.GetMembershipStore(cmd.Context())
organizationID, err := fctl.ResolveOrganizationID(cmd, store.Config, store.Client())
if err != nil {
return nil, err
}
_, err = store.Client().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
}