-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget.go
59 lines (51 loc) · 1.38 KB
/
get.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
package main
import (
"fmt"
"os"
)
var cmdGet = &Command{
UsageLine: "get [-T TargetDir] <path to project definition file>",
Short: "create the directory structure of a project according to project definition file",
Long: `
The get command parse the project definition file and downloads the relevant sources into current directory.
Running without any flag will search for a file called projectdef.toml in the current directory.
`,
CustomFlags: true,
}
var getT = cmdGet.Flag.String("T", "", "allow choosing a different directory")
func init() {
cmdGet.Run = runGet // break init loop
}
func create(s source, ch chan bool) {
fmt.Println("started on", s.Target)
s.SourceType.create(s.Target, s.Url, s.Branch)
fmt.Println("finished working on", s.Target)
ch <- true
}
func runGet(cmd *Command, args []string) {
config, err := proccessConfig(args[0]) // moved to proccessConfig.go to support additional types and keywords
if err != nil {
return
}
done := make(chan bool, len(config.Sources))
if *getT != "" {
os.Mkdir(*getT, 0777)
os.Chdir(*getT)
}
for _, source := range config.Sources {
source.set_type()
if source.Branch == "" {
if config.BaseBranch == "" {
source.Branch = source.SourceType.BaseBranchName
} else {
source.Branch = config.BaseBranch
}
}
go create(source, done)
}
var wait = len(config.Sources)
for wait > 0 {
<-done
wait -= 1
}
}