forked from 99designs/smartling
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdo_files_pull.go
56 lines (46 loc) · 910 Bytes
/
do_files_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
package main
import (
"github.com/Smartling/api-sdk-go"
)
func doFilesPull(
client *smartling.Client,
config Config,
args map[string]interface{},
) error {
var (
project = config.ProjectID
uri, _ = args["<uri>"].(string)
)
if args["--format"] == nil {
args["--format"] = defaultFilePullFormat
}
var (
err error
files []smartling.File
)
if uri == "-" {
files, err = readFilesFromStdin()
if err != nil {
return err
}
} else {
files, err = globFilesRemote(client, project, uri)
if err != nil {
return err
}
}
pool := NewThreadPool(config.Threads)
for _, file := range files {
// func closure required to pass different file objects to goroutines
func(file smartling.File) {
pool.Do(func() {
err := downloadFileTranslations(client, config, args, file)
if err != nil {
logger.Error(err)
}
})
}(file)
}
pool.Wait()
return nil
}