| 187 | } |
| 188 | |
| 189 | func 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. |
| 234 | func (opts *OpenOptions) structuredOutput() bool { |