func AddonsAddAutoComplete(c *cli.Context) error { resources, err := api.AddonProvidersList() if len(os.Args) > 1 && err == nil { lastArg := os.Args[len(os.Args)-2] isAddonNameSet := false for _, resource := range resources { if lastArg == resource.ID { isAddonNameSet = true break } } if isAddonNameSet { plans, err := api.AddonProviderPlansList(lastArg) if err == nil { for _, plan := range plans { fmt.Println(plan.Name) } } } else { for _, resource := range resources { fmt.Println(resource.ID) } } } return nil }
func checkPlanExist(addon, plan string) (string, error) { plans, err := api.AddonProviderPlansList(addon) if err != nil { return "", errgo.Mask(err, errgo.Any) } for _, p := range plans { if plan == p.Name { return p.ID, nil } } return "", errors.New("plan " + plan + " doesn't exist for addon " + addon) }
func Plans(addon string) error { plans, err := api.AddonProviderPlansList(addon) if err != nil { return errgo.Mask(err, errgo.Any) } t := tablewriter.NewWriter(os.Stdout) t.SetHeader([]string{"ID", "Name", "Description"}) for _, plan := range plans { t.Append([]string{plan.Name, plan.DisplayName, plan.ShortDescription}) } t.Render() return nil }
func AddonsUpgradeAutoComplete(c *cli.Context) error { appName := CurrentAppCompletion(c) addonName := "" if appName == "" { return nil } resources, err := api.AddonsList(appName) if len(os.Args) > 1 && err == nil { lastArg := os.Args[len(os.Args)-2] isAddonIDSet := false for _, resource := range resources { if lastArg == resource.ResourceID { isAddonIDSet = true addonName = resource.AddonProvider.ID break } } if isAddonIDSet && addonName != "" { plans, err := api.AddonProviderPlansList(addonName) if err == nil { for _, plan := range plans { fmt.Println(plan.Name) } } } else { for _, resource := range resources { fmt.Println(resource.ResourceID) } } } return nil }