Skip to content

Commit b1312a7

Browse files
committed
subdir errors without template flag
1 parent e477a49 commit b1312a7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

cmd/project/create.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/slackapi/slack-cli/internal/logger"
2424
"github.com/slackapi/slack-cli/internal/pkg/create"
2525
"github.com/slackapi/slack-cli/internal/shared"
26+
"github.com/slackapi/slack-cli/internal/slackerror"
2627
"github.com/slackapi/slack-cli/internal/slacktrace"
2728
"github.com/slackapi/slack-cli/internal/style"
2829
"github.com/spf13/cobra"
@@ -131,6 +132,12 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []
131132
return listTemplates(ctx, clients, categoryShortcut)
132133
}
133134

135+
// --subdir requires --template
136+
if cmd.Flags().Changed("subdir") && !templateFlagProvided {
137+
return slackerror.New(slackerror.ErrMismatchedFlags).
138+
WithMessage("the --subdir flag requires the --template flag")
139+
}
140+
134141
// Collect the template URL or select a starting template
135142
template, err := promptTemplateSelection(cmd, clients, categoryShortcut)
136143
if err != nil {

cmd/project/create_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ func TestCreateCommand(t *testing.T) {
320320
cm.IO.AssertNotCalled(t, "SelectPrompt", mock.Anything, "Select an app:", mock.Anything, mock.Anything)
321321
},
322322
},
323+
"subdir without template flag returns error": {
324+
CmdArgs: []string{"--subdir", "apps/my-app"},
325+
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
326+
createClientMock = new(CreateClientMock)
327+
CreateFunc = createClientMock.Create
328+
},
329+
ExpectedErrorStrings: []string{"the --subdir flag requires the --template flag"},
330+
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
331+
createClientMock.AssertNotCalled(t, "Create", mock.Anything, mock.Anything, mock.Anything, mock.Anything)
332+
},
333+
},
323334
"passes subdir flag to create function": {
324335
CmdArgs: []string{"--template", "slack-samples/bolt-js-starter-template", "--subdir", "apps/my-app"},
325336
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {

0 commit comments

Comments
 (0)