Skip to content

Commit 75f0d83

Browse files
authored
Merge pull request #81 from basecamp/setup-signup-routing
Route new users from setup to signup wizard
2 parents b39d446 + 5fc98bb commit 75f0d83

4 files changed

Lines changed: 58 additions & 12 deletions

File tree

internal/commands/format_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,26 @@ func TestFormatFlagsNewRegistered(t *testing.T) {
519519
}
520520

521521
func TestSetupBlockedInMachineMode(t *testing.T) {
522-
defer ResetTestMode()
523-
ResetTestMode()
524-
cfgAgent = true
525-
err := runSetup(setupCmd, nil)
526-
if err == nil {
527-
t.Fatal("expected error when running setup with --agent")
528-
}
529-
if !strings.Contains(err.Error(), "interactive terminal") {
530-
t.Errorf("unexpected error: %v", err)
522+
for _, tc := range []struct {
523+
name string
524+
set func()
525+
}{
526+
{"agent", func() { cfgAgent = true }},
527+
{"json", func() { cfgJSON = true }},
528+
{"quiet", func() { cfgQuiet = true }},
529+
} {
530+
t.Run(tc.name, func(t *testing.T) {
531+
defer ResetTestMode()
532+
ResetTestMode()
533+
tc.set()
534+
err := runSetup(setupCmd, nil)
535+
if err == nil {
536+
t.Fatal("expected error when running setup in machine mode")
537+
}
538+
if !strings.Contains(err.Error(), "interactive terminal") {
539+
t.Errorf("unexpected error: %v", err)
540+
}
541+
})
531542
}
532543
}
533544

internal/commands/setup.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Board struct {
2828
var setupCmd = &cobra.Command{
2929
Use: "setup",
3030
Short: "Interactive setup wizard",
31-
Long: "Configure Fizzy CLI with your API token, account, and default board.",
31+
Long: "Configure Fizzy CLI with your API token, account, and default board.\nNew users without an account will be guided through signup.",
3232
RunE: runSetup,
3333
}
3434

@@ -46,6 +46,26 @@ func runSetup(cmd *cobra.Command, args []string) error {
4646
fmt.Println("Welcome to Fizzy CLI setup!")
4747
fmt.Println()
4848

49+
// Ask if user has an account before checking existing config
50+
var hasAccount string
51+
err := huh.NewSelect[string]().
52+
Title("Do you have a Fizzy account?").
53+
Options(
54+
huh.NewOption("Yes, I have an account", "yes"),
55+
huh.NewOption("No, I'd like to sign up", "no"),
56+
).
57+
Value(&hasAccount).
58+
Run()
59+
60+
if err != nil {
61+
fmt.Println("Setup cancelled.")
62+
return nil //nolint:nilerr // user cancelled prompt
63+
}
64+
65+
if hasAccount == "no" {
66+
return signupWizard()
67+
}
68+
4969
// Check for existing config
5070
globalExists := config.Exists()
5171
localPath := config.LocalConfigPath()
@@ -57,7 +77,7 @@ func runSetup(cmd *cobra.Command, args []string) error {
5777
configLocation = "local config (" + localPath + ")"
5878
}
5979

60-
err := huh.NewConfirm().
80+
err = huh.NewConfirm().
6181
Title(fmt.Sprintf("Existing %s found. Reconfigure?", configLocation)).
6282
Value(&reconfigure).
6383
Run()
@@ -75,7 +95,7 @@ func runSetup(cmd *cobra.Command, args []string) error {
7595

7696
// Ask hosted vs self-hosted
7797
var hostingType string
78-
err := huh.NewSelect[string]().
98+
err = huh.NewSelect[string]().
7999
Title("Are you using the hosted or self-hosted version?").
80100
Options(
81101
huh.NewOption("Hosted (app.fizzy.do)", "hosted"),

internal/commands/setup_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ package commands
33
import (
44
"os"
55
"path/filepath"
6+
"strings"
67
"testing"
78

89
"github.com/basecamp/fizzy-cli/internal/config"
910
"gopkg.in/yaml.v3"
1011
)
1112

13+
func TestSetupCommandDescription(t *testing.T) {
14+
t.Run("long description mentions signup for new users", func(t *testing.T) {
15+
if !strings.Contains(setupCmd.Long, "signup") {
16+
t.Error("expected setup command long description to mention signup")
17+
}
18+
})
19+
}
20+
1221
func TestParseAccounts(t *testing.T) {
1322
t.Run("parses accounts from identity response", func(t *testing.T) {
1423
data := map[string]any{

internal/commands/signup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ func runSignup(cmd *cobra.Command, args []string) error {
112112
fmt.Println("Welcome to Fizzy CLI signup!")
113113
fmt.Println()
114114

115+
return signupWizard()
116+
}
117+
118+
// signupWizard contains the core interactive signup flow (steps 1-9).
119+
// Called by both runSignup and runSetup to avoid duplicate preamble.
120+
func signupWizard() error {
115121
// Step 1: Hosting type
116122
var hostingType string
117123
err := huh.NewSelect[string]().

0 commit comments

Comments
 (0)