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

Function PromptRegion

pkg/cmd/shared/apputil/create.go:70–108  ·  view source on GitHub ↗

PromptRegion fetches regions from the API and prompts the user to select one.

(
	io *iostreams.IOStreams,
	client *dashboard.Client,
	accessToken string,
)

Source from the content-addressed store, hash-verified

68
69// PromptRegion fetches regions from the API and prompts the user to select one.
70func PromptRegion(
71 io *iostreams.IOStreams,
72 client *dashboard.Client,
73 accessToken string,
74) (string, error) {
75 io.StartProgressIndicatorWithLabel("Fetching regions")
76 regions, err := client.ListRegions(accessToken)
77 io.StopProgressIndicator()
78 if err != nil {
79 return "", fmt.Errorf("failed to fetch regions: %w", err)
80 }
81
82 if len(regions) == 0 {
83 return "", fmt.Errorf("no regions available")
84 }
85
86 regionOptions := make([]string, len(regions))
87 for i, r := range regions {
88 if r.Name != "" {
89 regionOptions[i] = fmt.Sprintf("%s (%s)", r.Code, r.Name)
90 } else {
91 regionOptions[i] = r.Code
92 }
93 }
94
95 var selected int
96 err = prompt.SurveyAskOne(
97 &survey.Select{
98 Message: "Region:",
99 Options: regionOptions,
100 },
101 &selected,
102 )
103 if err != nil {
104 return "", err
105 }
106
107 return regions[selected].Code, nil
108}
109
110// CreateAndFetchApplication creates an application (with region retry) and
111// generates an API key for it. It returns the region the application was

Callers 1

Calls 4

ListRegionsMethod · 0.80
StopProgressIndicatorMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected