addonUUIDFromFlags returns the addon UUID based on the --addon flag, the SCALINGO_ADDON env var or the current detected database. exitIfMissing is optional. Set to true to show a message requesting for the --addon flag.
(ctx context.Context, c *cli.Command, app string, exitIfMissing ...bool)
| 51 | // or the current detected database. |
| 52 | // exitIfMissing is optional. Set to true to show a message requesting for the --addon flag. |
| 53 | func addonUUIDFromFlags(ctx context.Context, c *cli.Command, app string, exitIfMissing ...bool) string { |
| 54 | var addonName string |
| 55 | |
| 56 | for _, cliContext := range c.Lineage() { |
| 57 | if cliContext.String("addon") != "<addon_id>" { |
| 58 | addonName = cliContext.String("addon") |
| 59 | break |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if addonName == "" && os.Getenv("SCALINGO_ADDON") != "" { |
| 64 | addonName = os.Getenv("SCALINGO_ADDON") |
| 65 | } |
| 66 | |
| 67 | if addonName == "" && os.Getenv("SCALINGO_PREVIEW_FEATURES") == "true" { |
| 68 | _, addonName = detect.GetCurrentResourceAndDatabase(ctx, c) |
| 69 | } |
| 70 | |
| 71 | if addonName == "" && len(exitIfMissing) > 0 && exitIfMissing[0] { |
| 72 | io.Error("Unable to find the addon name, please use --addon flag.") |
| 73 | os.Exit(1) |
| 74 | } |
| 75 | if addonName == "" { |
| 76 | return "" |
| 77 | } |
| 78 | |
| 79 | var addonUUID string |
| 80 | var err error |
| 81 | addonUUID, err = utils.GetAddonUUIDFromType(ctx, app, addonName) |
| 82 | if err != nil { |
| 83 | io.Error("Unable to get the addon UUID based on its type:", err) |
| 84 | os.Exit(1) |
| 85 | } |
| 86 | debug.Println("[ADDON] Addon name is", addonName) |
| 87 | return addonUUID |
| 88 | } |
| 89 | |
| 90 | func regionNameFromFlags(c *cli.Command) string { |
| 91 | for _, cliContext := range c.Lineage() { |
no test coverage detected