-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (37 loc) · 1.05 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/grafana/go-depsync/deps"
)
func main() {
gomod := flag.String("gomod", "./go.mod", "Path to the local go.mod file")
parent := flag.String("parent", "", "Name of the parent package to sync dependencies with")
flag.Parse()
if *parent == "" {
flag.Usage()
log.Fatalf("You must specify the name of the parent package")
}
ownDeps, err := deps.FromGomodFile(*gomod)
if err != nil {
log.Fatalf("Couldn't parse own dependencies: %v", err)
}
parentVer, hasParent := ownDeps[*parent]
if !hasParent {
log.Fatalf("Parent package %q not found in local go.mod %q", *parent, *gomod)
}
log.Printf("Found parent %s@%s", *parent, parentVer)
parentDeps, err := deps.FromModule(*parent, parentVer)
if err != nil {
log.Fatalf("Cannot parse dependencies of %q: %v", *parent, err)
}
mismatched := deps.Mismatched(ownDeps, parentDeps)
if len(mismatched) == 0 {
return
}
deps.WriteVersionTable(os.Stderr, ownDeps, mismatched)
fmt.Fprintln(os.Stderr)
fmt.Println(deps.GoGetCommand(mismatched))
}