MCPcopy Create free account
hub / github.com/Scalingo/cli / CollaboratorsAddAutoComplete

Function CollaboratorsAddAutoComplete

cmd/autocomplete/collaborators_add.go:16–82  ·  view source on GitHub ↗
(ctx context.Context, c *cli.Command)

Source from the content-addressed store, hash-verified

14)
15
16func CollaboratorsAddAutoComplete(ctx context.Context, c *cli.Command) error {
17 var err error
18 appName := CurrentAppCompletion(ctx, c)
19 if appName == "" {
20 return nil
21 }
22
23 apps, err := appsList(ctx)
24 if err != nil {
25 debug.Println("fail to get apps list:", err)
26 return nil
27 }
28
29 client, err := config.ScalingoClient(ctx)
30 if err != nil {
31 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
32 }
33 currentAppCollaborators, err := client.CollaboratorsList(ctx, appName)
34 if err != nil {
35 return nil
36 }
37
38 var apiError error
39 ch := make(chan string)
40 var wg sync.WaitGroup
41 wg.Add(len(apps))
42 for _, app := range apps {
43 go func(app *scalingo.App) {
44 defer wg.Done()
45 appCollaborators, erro := client.CollaboratorsList(ctx, app.Name)
46 if erro != nil {
47 config.C.Logger.Println(erro.Error())
48 apiError = erro
49 return
50 }
51 for _, col := range appCollaborators {
52 ch <- col.Email
53 }
54 }(app)
55 }
56
57 setEmails := make(map[string]bool)
58 go func() {
59 for content := range ch {
60 setEmails[content] = true
61 }
62 }()
63 wg.Wait()
64 close(ch)
65
66 if apiError != nil {
67 return nil
68 }
69
70 for email := range setEmails {
71 isAlreadyCollaborator := false
72 for _, currentAppCol := range currentAppCollaborators {
73 if currentAppCol.Email == email {

Callers 1

collaborators.goFile · 0.92

Calls 4

ScalingoClientFunction · 0.92
CurrentAppCompletionFunction · 0.85
appsListFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected