()
| 12 | ) |
| 13 | |
| 14 | func newSetupCommand() *cobra.Command { |
| 15 | return &cobra.Command{ |
| 16 | Use: "setup", |
| 17 | Short: "First-run setup wizard", |
| 18 | Long: "Walks through initial authentication setup for hey CLI.", |
| 19 | Annotations: map[string]string{ |
| 20 | "agent_notes": "Run this on first use. Performs OAuth login. Equivalent to hey auth login.", |
| 21 | }, |
| 22 | RunE: func(cmd *cobra.Command, args []string) error { |
| 23 | if authMgr.IsAuthenticated() { |
| 24 | if writer.IsStyled() { |
| 25 | fmt.Fprintln(cmd.OutOrStdout(), "Already authenticated. Run `hey auth status` for details.") |
| 26 | return nil |
| 27 | } |
| 28 | return writeOK(map[string]string{"status": "already_authenticated"}, |
| 29 | output.WithSummary("Already authenticated"), |
| 30 | ) |
| 31 | } |
| 32 | |
| 33 | if writer.IsStyled() { |
| 34 | w := cmd.OutOrStdout() |
| 35 | fmt.Fprintln(w, "Welcome to hey CLI!") |
| 36 | fmt.Fprintln(w) |
| 37 | fmt.Fprintln(w, "Let's get you logged in...") |
| 38 | fmt.Fprintln(w) |
| 39 | } |
| 40 | |
| 41 | ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute) |
| 42 | defer cancel() |
| 43 | |
| 44 | if err := authMgr.Login(ctx, auth.LoginOptions{}); err != nil { |
| 45 | return output.ErrAuth(fmt.Sprintf("login failed: %v", err)) |
| 46 | } |
| 47 | |
| 48 | if writer.IsStyled() { |
| 49 | w := cmd.OutOrStdout() |
| 50 | fmt.Fprintln(w, "Setup complete! You're ready to use hey.") |
| 51 | fmt.Fprintln(w) |
| 52 | fmt.Fprintln(w, "Try: hey boxes") |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | return writeOK(map[string]string{"status": "setup_complete"}, |
| 57 | output.WithSummary("Setup complete"), |
| 58 | output.WithBreadcrumbs(output.Breadcrumb{ |
| 59 | Action: "start", |
| 60 | Command: "hey boxes", |
| 61 | Description: "List your mailboxes", |
| 62 | }), |
| 63 | ) |
| 64 | }, |
| 65 | } |
| 66 | } |
no test coverage detected