MCPcopy Create free account
hub / github.com/algolia/cli / PickPlan

Function PickPlan

pkg/cmd/shared/apputil/plan.go:115–134  ·  view source on GitHub ↗

PickPlan shows an interactive selector over the candidate plans.

(candidates []dashboard.Plan)

Source from the content-addressed store, hash-verified

113
114// PickPlan shows an interactive selector over the candidate plans.
115func PickPlan(candidates []dashboard.Plan) (*dashboard.Plan, error) {
116 if len(candidates) == 0 {
117 return nil, fmt.Errorf("no plans are available")
118 }
119 labels := make([]string, len(candidates))
120 for i, p := range candidates {
121 labels[i] = fmt.Sprintf("%s — %s", p.Name, p.Price)
122 }
123 var selected int
124 if err := prompt.SurveyAskOne(
125 &survey.Select{
126 Message: "Select a plan:",
127 Options: labels,
128 },
129 &selected,
130 ); err != nil {
131 return nil, err
132 }
133 return &candidates[selected], nil
134}

Callers 1

selectPlanFunction · 0.92

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected