MCPcopy Create free account
hub / github.com/Scalingo/cli / Destroy

Function Destroy

addons/destroy.go:14–51  ·  view source on GitHub ↗
(ctx context.Context, app, addonID string)

Source from the content-addressed store, hash-verified

12)
13
14func Destroy(ctx context.Context, app, addonID string) error {
15 if app == "" {
16 return errors.New(ctx, "no app defined")
17 } else if addonID == "" {
18 return errors.New(ctx, "no addon ID defined")
19 }
20
21 c, err := config.ScalingoClient(ctx)
22 if err != nil {
23 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
24 }
25
26 addon, err := checkAddonExists(ctx, c, app, addonID)
27 if err != nil {
28 return errors.Wrap(ctx, err, "check addon exists")
29 }
30
31 io.Status("Destroy", addonID)
32 io.Warning("This operation is irreversible")
33 io.Warning("All related data will be destroyed")
34 io.Info("To confirm, type the ID of the addon:")
35 fmt.Print("-----> ")
36
37 var validationName string
38 fmt.Scan(&validationName)
39
40 if validationName != addonID {
41 return errors.Newf(ctx, "'%s' is not '%s', aborting…\n", validationName, addonID)
42 }
43
44 err = c.AddonDestroy(ctx, app, addon.ID)
45 if err != nil {
46 return errors.Wrap(ctx, err, "addon destroy")
47 }
48
49 io.Status("Addon", addonID, "has been destroyed")
50 return nil
51}
52
53func checkAddonExists(ctx context.Context, c *scalingo.Client, app, addonID string) (*scalingo.Addon, error) {
54 resources, err := c.AddonsList(ctx, app)

Callers 1

addons.goFile · 0.92

Calls 5

ScalingoClientFunction · 0.92
StatusFunction · 0.92
WarningFunction · 0.92
InfoFunction · 0.92
checkAddonExistsFunction · 0.85

Tested by

no test coverage detected