Esempio n. 1
0
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
}
Esempio n. 2
0
File: list.go Progetto: yannski/cli
func List() error {
	addonProviders, err := api.AddonProvidersList()
	if err != nil {
		return errgo.Mask(err, errgo.Any)
	}
	t := tablewriter.NewWriter(os.Stdout)
	t.SetHeader([]string{"ID", "Name"})

	for _, addon := range addonProviders {
		t.Append([]string{addon.ID, addon.Name})
	}

	t.Render()
	return nil
}