── Commands (async) ──────────────────────────────────────────────────────────
(client *api.Client)
| 538 | // ── Commands (async) ────────────────────────────────────────────────────────── |
| 539 | |
| 540 | func startAuthCmd(client *api.Client) tea.Cmd { |
| 541 | return func() tea.Msg { |
| 542 | tokenResp, err := client.GenerateToken() |
| 543 | if err != nil { |
| 544 | return authResultMsg{err: err} |
| 545 | } |
| 546 | |
| 547 | authURL := fmt.Sprintf("%s?token=%s&exchange=%s", api.CLIBaseURL, tokenResp.AccessToken, tokenResp.ExchangeCode) |
| 548 | browser.OpenURL(authURL) |
| 549 | |
| 550 | const maxAttempts = 150 |
| 551 | for i := 0; i < maxAttempts; i++ { |
| 552 | time.Sleep(2 * time.Second) |
| 553 | resp, err := client.ExchangeToken(tokenResp.ExchangeCode) |
| 554 | if err != nil { |
| 555 | continue |
| 556 | } |
| 557 | if resp.CliID != nil && resp.APIKey != nil { |
| 558 | return authResultMsg{cliID: *resp.CliID, apiKey: *resp.APIKey} |
| 559 | } |
| 560 | if resp.Status != nil && *resp.Status == "expired" { |
| 561 | return authResultMsg{err: fmt.Errorf("authentication token expired")} |
| 562 | } |
| 563 | } |
| 564 | return authResultMsg{err: fmt.Errorf("authentication timed out")} |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | func downloadMetadataCmd(client *api.Client) tea.Cmd { |
| 569 | return func() tea.Msg { |
no test coverage detected