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

Function selectPlan

pkg/cmd/application/create/create.go:360–402  ·  view source on GitHub ↗

selectPlan resolves the target plan from --plan or an interactive picker.

(
	opts *CreateOptions,
	plans []dashboard.Plan,
	user *dashboard.DashboardUser,
)

Source from the content-addressed store, hash-verified

358
359// selectPlan resolves the target plan from --plan or an interactive picker.
360func selectPlan(
361 opts *CreateOptions,
362 plans []dashboard.Plan,
363 user *dashboard.DashboardUser,
364) (*dashboard.Plan, error) {
365 if opts.Plan != "" {
366 target, err := apputil.ResolvePlan(plans, opts.Plan)
367 if err == nil {
368 return target, nil
369 }
370 if paid := apputil.KnownPaidPlan(opts.Plan); paid != nil {
371 return paid, nil
372 }
373 return nil, err
374 }
375
376 if !opts.IO.CanPrompt() {
377 free := apputil.FindFreePlan(plans)
378 if free == nil {
379 return nil, fmt.Errorf(
380 "no free plan is available; pass --plan to choose one of: %s",
381 strings.Join(apputil.PlanChoices(plans), ", "),
382 )
383 }
384 return free, nil
385 }
386
387 hideNonFree := user != nil && !user.HasPaymentMethod
388 candidates := apputil.SelectablePlans(plans, hideNonFree)
389 if len(candidates) == 0 {
390 return nil, fmt.Errorf("no self-serve plans are available")
391 }
392 if hideNonFree {
393 fmt.Fprintln(
394 opts.IO.Out,
395 "No payment method on file — only the Free plan is available. Add billing in the Algolia dashboard to unlock paid plans.",
396 )
397 }
398 if len(candidates) == 1 {
399 return &candidates[0], nil
400 }
401 return apputil.PickPlan(candidates)
402}
403
404// confirmToS shows the plan's terms and returns whether they were accepted.
405func confirmToS(opts *CreateOptions, plan dashboard.Plan) (bool, error) {

Callers 1

createApplicationFunction · 0.85

Calls 8

ResolvePlanFunction · 0.92
KnownPaidPlanFunction · 0.92
FindFreePlanFunction · 0.92
PlanChoicesFunction · 0.92
SelectablePlansFunction · 0.92
PickPlanFunction · 0.92
CanPromptMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected