Skip to content

Commit a120396

Browse files
committed
fix: edge case
1 parent 7b610e5 commit a120396

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

cmd/project/create.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,21 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []
138138
}
139139

140140
// Prompt for app name if not provided via flag or argument
141-
if appNameArg == "" && clients.IO.IsTTY() {
142-
defaultName := generateRandomAppName()
143-
cmd.Print(style.Secondary(fmt.Sprintf(" Press Enter to use the generated name: %s", defaultName)), "\n")
144-
name, err := clients.IO.InputPrompt(ctx, "Name your app:", iostreams.InputPromptConfig{})
145-
if err != nil {
146-
return err
147-
}
148-
if name != "" {
149-
appNameArg = name
141+
if appNameArg == "" {
142+
if clients.IO.IsTTY() {
143+
defaultName := generateRandomAppName()
144+
cmd.Print(style.Secondary(fmt.Sprintf(" Press Enter to use the generated name: %s", defaultName)), "\n")
145+
name, err := clients.IO.InputPrompt(ctx, "Name your app:", iostreams.InputPromptConfig{})
146+
if err != nil {
147+
return err
148+
}
149+
if name != "" {
150+
appNameArg = name
151+
} else {
152+
appNameArg = defaultName
153+
}
150154
} else {
151-
appNameArg = defaultName
155+
appNameArg = generateRandomAppName()
152156
}
153157
}
154158

cmd/project/create_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,39 @@ func TestCreateCommand(t *testing.T) {
379379
}))
380380
},
381381
},
382+
"non-TTY without name falls back to generated name": {
383+
CmdArgs: []string{"--template", "slack-samples/bolt-js-starter-template"},
384+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
385+
// IsTTY defaults to false via AddDefaultMocks, simulating piped output
386+
cm.IO.On("SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything).
387+
Return(
388+
iostreams.SelectPromptResponse{
389+
Flag: true,
390+
Option: "slack-samples/bolt-js-starter-template",
391+
},
392+
nil,
393+
)
394+
cm.IO.On("SelectPrompt", mock.Anything, "Select a language:", mock.Anything, mock.Anything).
395+
Return(
396+
iostreams.SelectPromptResponse{
397+
Flag: true,
398+
Option: "slack-samples/bolt-js-starter-template",
399+
},
400+
nil,
401+
)
402+
createClientMock = new(CreateClientMock)
403+
createClientMock.On("Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return("", nil)
404+
CreateFunc = createClientMock.Create
405+
},
406+
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
407+
// Should NOT prompt for name since not a TTY
408+
cm.IO.AssertNotCalled(t, "InputPrompt", mock.Anything, "Name your app:", mock.Anything)
409+
// Should still call Create with a non-empty generated name
410+
createClientMock.AssertCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, mock.MatchedBy(func(args create.CreateArgs) bool {
411+
return args.AppName != ""
412+
}))
413+
},
414+
},
382415
"positional arg skips name prompt": {
383416
CmdArgs: []string{"my-project"},
384417
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {

0 commit comments

Comments
 (0)