MCPcopy Create free account
hub / github.com/Scalingo/cli / AddonsAddAutoComplete

Function AddonsAddAutoComplete

cmd/autocomplete/addons_add.go:13–46  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

11)
12
13func AddonsAddAutoComplete(ctx context.Context) error {
14 client, err := config.ScalingoClient(ctx)
15 if err != nil {
16 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
17 }
18 resources, err := client.AddonProvidersList(ctx)
19 if len(os.Args) > 1 && err == nil {
20 lastArg := os.Args[len(os.Args)-2]
21 isAddonNameSet := false
22
23 for _, resource := range resources {
24 if lastArg == resource.ID {
25 isAddonNameSet = true
26 break
27 }
28 }
29
30 if isAddonNameSet {
31 plans, err := client.AddonProviderPlansList(ctx, lastArg, scalingo.AddonProviderPlansListOpts{})
32
33 if err == nil {
34 for _, plan := range plans {
35 fmt.Println(plan.Name)
36 }
37 }
38 } else {
39 for _, resource := range resources {
40 fmt.Println(resource.ID)
41 }
42 }
43 }
44
45 return nil
46}

Callers 1

addons.goFile · 0.92

Calls 1

ScalingoClientFunction · 0.92

Tested by

no test coverage detected