-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (47 loc) · 1.24 KB
/
main.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
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"strings"
)
var in = flag.String("in", "Godeps.json", "The Godeps.json file that you want to convert")
// Godeps describes what a package needs to be rebuilt reproducibly.
// It's the same information stored in file Godeps.
type Godeps struct {
ImportPath string
Deps []Dependency
}
type Dependency struct {
ImportPath string
Comment string `json:",omitempty"` // Description of commit, if present.
Rev string // VCS-specific commit ID.
}
func main() {
flag.Parse()
godep, err := os.Open(*in)
if err != nil {
log.Fatalf("error opening file: %s", err)
}
var parsed Godeps
if err := json.NewDecoder(godep).Decode(&parsed); err != nil {
log.Fatalf("error parsing json: %s", err)
}
template := "[[override]]\n name = \"%s\"\n version = \"%s\"\n\n"
deps := make(map[string]string)
for _, dep := range parsed.Deps {
splitted := strings.SplitN(dep.ImportPath, "/", 4)
repo := ""
if len(splitted) >= 3 {
repo = fmt.Sprintf("%s/%s/%s", splitted[0], splitted[1], splitted[2])
} else {
repo = fmt.Sprintf("%s/%s", splitted[0], splitted[1])
}
deps[repo] = dep.Rev
}
for repo, version := range deps {
fmt.Printf(template, repo, version)
}
}