Example #1
0
func checkAddonExist(app, resourceID string) (*api.Addon, error) {
	resources, err := api.AddonsList(app)
	if err != nil {
		return nil, errgo.Mask(err, errgo.Any)
	}
	addonList := []string{}
	for _, r := range resources {
		addonList = append(addonList, r.ResourceID+" ("+r.AddonProvider.Name+")")
		if resourceID == r.ResourceID {
			return r, nil
		}
	}
	return nil, errgo.Newf("Addon "+resourceID+" doesn't exist for app "+app+"\nExisting addons:\n  - %v", strings.Join(addonList, "\n  - "))
}
Example #2
0
func AddonsPlansAutoComplete(c *cli.Context) error {
	appName := CurrentAppCompletion(c)
	if appName == "" {
		return nil
	}

	resources, err := api.AddonsList(appName)
	if err == nil {
		for _, resource := range resources {
			fmt.Println(resource.AddonProvider.ID)
		}
	}

	return nil
}
Example #3
0
File: list.go Project: yannski/cli
func List(app string) error {
	resources, err := api.AddonsList(app)
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}

	t := tablewriter.NewWriter(os.Stdout)
	t.SetHeader([]string{"Addon", "ID", "Plan"})

	for _, resource := range resources {
		t.Append([]string{resource.AddonProvider.Name, resource.ResourceID, resource.Plan.Name})
	}
	t.Render()

	return nil

}
Example #4
0
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
}