MCPcopy Create free account
hub / github.com/basecamp/hey-cli / newSetupCommand

Function newSetupCommand

internal/cmd/setup.go:14–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func 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}

Callers 1

newRootCmdFunction · 0.85

Calls 6

WithSummaryFunction · 0.92
WithBreadcrumbsFunction · 0.92
writeOKFunction · 0.85
IsAuthenticatedMethod · 0.80
IsStyledMethod · 0.80
LoginMethod · 0.80

Tested by

no test coverage detected