-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaster-composer.go
86 lines (69 loc) · 1.89 KB
/
faster-composer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"os"
"cmp"
"encoding/json"
"os/exec"
)
func routine(repository cmp.RepositoryInfo, c chan cmp.PackagistInfo) {
packagistInfo := cmp.GetPackagistInfo(repository)
c <- packagistInfo
}
func downloadTest(url string, c chan DownloadProgress, lineNumber int) {
text := fmt.Sprintf("Cloning package: %s", url)
cmp.EchoAtLine(text, lineNumber)
cmd := exec.Command("git", "clone", url)
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
cmd.Run()
cmd.Wait()
progress := new(DownloadProgress)
progress.id = lineNumber
c <- *progress
}
type DownloadProgress struct {
id int
}
func main() {
currentPath, _ := os.Getwd()
filePath := currentPath + "/testfiles/composer.json"
composerInfo, err := cmp.ReadComposerJson(filePath)
if err != nil {
panic(err)
}
fmt.Printf("read composer.json: %#v\n", composerInfo)
var parsedTestData []string
testData := []byte(`
[
"https://github.com/symfony/symfony.git",
"https://github.com/symfony/web-profiler-bundle.git",
"https://github.com/doctrine/doctrine2.git",
"https://github.com/symfony/yaml.git",
"https://github.com/artdarek/ga-4-laravel.git",
"https://github.com/doctrine/instantiator.git",
"https://github.com/doctrine/collections.git"
]
`)
json.Unmarshal(testData, &parsedTestData)
downloadChannel := make(chan DownloadProgress)
lineNumber, _ := cmp.GetCursorPosition()
runningProcedures := 0
for _, value := range parsedTestData {
go downloadTest(value, downloadChannel, lineNumber)
runningProcedures = runningProcedures + 1
lineNumber = lineNumber + 1
}
for {
if runningProcedures <= 0 {
break
}
downloadProgress := <- downloadChannel
if downloadProgress.id > 0 {
text := fmt.Sprintf("Download finished at: %d", downloadProgress.id)
cmp.EchoAtLine(text, downloadProgress.id)
runningProcedures = runningProcedures - 1
}
}
fmt.Println("\nDownloading complete!")
}