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

Function runOpenCmd

pkg/cmd/open/open.go:189–231  ·  view source on GitHub ↗
(opts *OpenOptions)

Source from the content-addressed store, hash-verified

187}
188
189func runOpenCmd(opts *OpenOptions) error {
190 listing := opts.List || opts.Shortcut == ""
191
192 // With an output format, emit page metadata instead of opening a browser.
193 if opts.structuredOutput() {
194 return printTargets(opts, listing)
195 }
196
197 if listing {
198 return listTargets(opts)
199 }
200
201 // Resource shortcuts open directly, without sign-in. App-scoped resources
202 // (such as status) use the dashboard URL only when a profile application is
203 // configured and belongs to the signed-in account.
204 if resource, ok := resourceURLs[opts.Shortcut]; ok {
205 url := resource.Default
206 if resource.AppPath != "" {
207 if _, err := opts.config.Profile().GetApplicationID(); err == nil {
208 client := opts.NewDashboardClient(auth.OAuthClientID())
209 accessToken, err := opts.Authenticate(opts.IO, client)
210 if err != nil {
211 return err
212 }
213 appID, err := opts.resolveApplicationForAccount(client, accessToken)
214 if err != nil {
215 return err
216 }
217 if appID != "" {
218 url = fmt.Sprintf("%s/apps/%s/%s", client.DashboardURL, appID, resource.AppPath)
219 }
220 }
221 }
222 return opts.Browser(url)
223 }
224
225 // Application pages require sign-in and an application scope.
226 if target, ok := dashboardTargets[opts.Shortcut]; ok {
227 return openDashboardTarget(opts, target)
228 }
229
230 return unsupportedShortcutError(opts.Shortcut)
231}
232
233// structuredOutput reports whether an output format was requested via --output.
234func (opts *OpenOptions) structuredOutput() bool {

Calls 9

OAuthClientIDFunction · 0.92
printTargetsFunction · 0.85
listTargetsFunction · 0.85
openDashboardTargetFunction · 0.85
unsupportedShortcutErrorFunction · 0.85
GetApplicationIDMethod · 0.80
ProfileMethod · 0.65
structuredOutputMethod · 0.45