-
Notifications
You must be signed in to change notification settings - Fork 34
/
handle_update.go
68 lines (57 loc) · 1.22 KB
/
handle_update.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
package main
import (
"fmt"
"strings"
)
func handleUpdate(
recursive bool,
withTests bool,
dependencies []string,
) error {
var err error
if len(dependencies) == 0 {
dependencies, err = parseImports(recursive, withTests)
if err != nil {
return err
}
}
submodules, err := getVendorSubmodules()
if err != nil {
return err
}
updated := 0
for _, importpath := range dependencies {
parts := strings.Split(importpath, "=")
if len(parts) > 2 {
return fmt.Errorf("too many `=` delimiters: %s", importpath)
}
var version string
if len(parts) == 2 {
importpath = parts[0]
version = parts[1]
}
if _, ok := submodules[importpath]; !ok {
return fmt.Errorf("unknown dependency %s", importpath)
}
if version != "" {
logger.Infof("updating vendor submodule %s to %s", importpath, version)
} else {
logger.Infof("updating vendor submodule %s", importpath)
}
err := updateVendorSubmodule(importpath, version)
if err != nil {
return err
}
updated++
}
if updated > 0 {
if updated == 1 {
logger.Infof("updated 1 dependency submodule")
} else {
logger.Infof("updated %d dependencies submodules", updated)
}
} else {
logger.Infof("nothing to update")
}
return nil
}