-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.go
63 lines (50 loc) · 1.22 KB
/
pull.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"os"
"sync"
survey "gopkg.in/AlecAivazis/survey.v1"
)
// Pull displays and downloads any repos that are available
func Pull(args []string, _ []Command) error {
username, password, subreddit := GetCredentials()
session, err := GetSession(username, password)
if err != nil {
return err
}
manifest, err := RetrieveManifestFromReddit(subreddit, session)
if err != nil {
return err
}
var options []string
for _, repo := range manifest.Repositories {
options = append(options, repo.Name)
}
prompt := &survey.MultiSelect{
Message: "Select repositories to download",
Options: options,
}
response := []string{}
survey.AskOne(prompt, &response, nil)
path, err := os.Getwd()
if err != nil {
return err
}
repositories := manifest.FilterReposByNames(response)
var wg sync.WaitGroup
downloadResponses := make(chan error, len(repositories))
for _, repository := range repositories {
wg.Add(1)
go func(repository Repository) {
defer wg.Done()
downloadResponses <- repository.Download(path, session)
}(repository)
}
wg.Wait()
close(downloadResponses)
for downloadResponse := range downloadResponses {
if downloadResponse != nil {
return downloadResponse
}
}
return err
}