| 10 | ) |
| 11 | |
| 12 | func Set(ctx context.Context, app string, stack string) error { |
| 13 | c, err := config.ScalingoClient(ctx) |
| 14 | if err != nil { |
| 15 | return errors.Wrapf(ctx, err, "fail to get Scalingo client") |
| 16 | } |
| 17 | stacks, err := c.StacksList(ctx) |
| 18 | if err != nil { |
| 19 | return errors.Wrapf(ctx, err, "fail to list available stacks") |
| 20 | } |
| 21 | |
| 22 | var stackToSet scalingo.Stack |
| 23 | for _, apistack := range stacks { |
| 24 | if apistack.Name == stack || apistack.ID == stack { |
| 25 | stackToSet = apistack |
| 26 | break |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if stackToSet.ID == "" { |
| 31 | return errors.Newf(ctx, "stack '%v' is unknown.", stack) |
| 32 | } |
| 33 | |
| 34 | _, err = c.AppsSetStack(ctx, app, stackToSet.ID) |
| 35 | if err != nil { |
| 36 | return errors.Wrapf(ctx, err, "fail to set stack %v (%v)", stackToSet.Name, stackToSet.ID) |
| 37 | } |
| 38 | |
| 39 | io.Statusf("Stack of %v has been set to %v (%v)\n", io.Bold(app), io.Bold(stackToSet.Name), stackToSet.ID) |
| 40 | io.Infof(io.Gray("Deployment cache of %v has been reset\n"), app) |
| 41 | |
| 42 | return nil |
| 43 | } |