Skip to content

Commit b12ed2b

Browse files
committed
error out when flag not provided
1 parent 8e68452 commit b12ed2b

File tree

2 files changed

+9
-51
lines changed

2 files changed

+9
-51
lines changed

cmd/collaborators/update.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
package collaborators
1616

1717
import (
18-
"context"
18+
"fmt"
1919
"net/mail"
2020

2121
"github.com/opentracing/opentracing-go"
2222
"github.com/slackapi/slack-cli/internal/cmdutil"
23-
"github.com/slackapi/slack-cli/internal/iostreams"
2423
"github.com/slackapi/slack-cli/internal/prompts"
2524
"github.com/slackapi/slack-cli/internal/shared"
2625
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -59,7 +58,7 @@ func NewUpdateCommand(clients *shared.ClientFactory) *cobra.Command {
5958
"collaborator permission type\n(\"%s\" or \"%s\")",
6059
string(types.OWNER),
6160
string(types.READER),
62-
))```
61+
))
6362

6463
return cmd
6564
}
@@ -84,10 +83,8 @@ func runUpdateCommand(cmd *cobra.Command, clients *shared.ClientFactory, args []
8483
return err
8584
}
8685
} else {
87-
slackUser.PermissionType, err = promptCollaboratorPermissionSelection(ctx, clients)
88-
if err != nil {
89-
return err
90-
}
86+
cmd.Println(fmt.Sprintf("\n%s Specify a permission type for your collaborator with the %s flag\n", style.Emoji("warning"), style.Highlight("--permission-type")))
87+
return nil
9188
}
9289

9390
// Get the app auth selection from the flag or prompt
@@ -111,29 +108,3 @@ func runUpdateCommand(cmd *cobra.Command, clients *shared.ClientFactory, args []
111108

112109
return nil
113110
}
114-
115-
// promptCollaboratorPermissionSelection fetches collaborator permission from the prompt
116-
func promptCollaboratorPermissionSelection(
117-
ctx context.Context,
118-
clients *shared.ClientFactory,
119-
) (
120-
permission types.AppCollaboratorPermission,
121-
err error,
122-
) {
123-
permissionLabels := []string{
124-
"owner",
125-
"reader",
126-
}
127-
response, err := clients.IO.SelectPrompt(
128-
ctx,
129-
"Select a permission type",
130-
permissionLabels,
131-
iostreams.SelectPromptConfig{
132-
Required: true,
133-
},
134-
)
135-
if err != nil {
136-
return "", err
137-
}
138-
return types.StringToAppCollaboratorPermission(response.Option)
139-
}

cmd/collaborators/update_test.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"testing"
2020

21-
"github.com/slackapi/slack-cli/internal/iostreams"
2221
"github.com/slackapi/slack-cli/internal/prompts"
2322
"github.com/slackapi/slack-cli/internal/shared"
2423
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -59,26 +58,14 @@ func TestUpdateCommand(t *testing.T) {
5958
types.SlackUser{Email: "[email protected]", PermissionType: types.OWNER}).Return(nil)
6059
},
6160
},
62-
"prompts when permission type not specified": {
61+
"permission type must be specified": {
6362
CmdArgs: []string{"[email protected]"},
64-
ExpectedOutputs: []string{"[email protected] successfully updated as a reader collaborator on this app"},
63+
ExpectedOutputs: []string{"Specify a permission type for your collaborator"},
6564
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
6665
clientsMock.AddDefaultMocks()
67-
// Mock app selection
68-
appSelectMock := prompts.NewAppSelectMock()
69-
appSelectPromptFunc = appSelectMock.AppSelectPrompt
70-
appSelectMock.On("AppSelectPrompt", mock.Anything, mock.Anything, prompts.ShowHostedOnly, prompts.ShowInstalledAndUninstalledApps).Return(prompts.SelectedApp{App: types.App{AppID: "A123"}, Auth: types.SlackAuth{}}, nil)
71-
// Mock permission selection prompt
72-
clientsMock.IO.On("SelectPrompt", mock.Anything, "Select a permission type", mock.Anything, mock.Anything).Return(
73-
iostreams.SelectPromptResponse{
74-
Prompt: true,
75-
Option: "reader",
76-
Index: 1,
77-
}, nil)
78-
// Mock API call
79-
clientsMock.API.On("UpdateCollaborator", mock.Anything, mock.Anything,
80-
"A123",
81-
types.SlackUser{Email: "[email protected]", PermissionType: types.READER}).Return(nil)
66+
// Set experiment flag
67+
clientsMock.Config.ExperimentsFlag = append(clientsMock.Config.ExperimentsFlag, "read-only-collaborators")
68+
clientsMock.Config.LoadExperiments(ctx, clientsMock.IO.PrintDebug)
8269
},
8370
},
8471
"user ID must be provided": {

0 commit comments

Comments
 (0)