-
Notifications
You must be signed in to change notification settings - Fork 34
/
handle_query.go
48 lines (39 loc) · 913 Bytes
/
handle_query.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 (
"fmt"
"strconv"
)
func handleQuery(recursive, withTests, onlyVendored bool) error {
submodules, err := getVendorSubmodules()
if err != nil {
return err
}
if onlyVendored {
maxlength := getMaxLength(getKeys(submodules))
format := "%-" + strconv.Itoa(maxlength) + "s %s\n"
for submodule, commit := range submodules {
fmt.Printf(format, submodule, commit)
}
} else {
imports, err := parseImports(recursive, withTests)
if err != nil {
return err
}
maxlength := 0
if len(submodules) > 0 {
maxlength = getMaxLength(
append(getKeys(submodules), imports...),
)
}
vendoredFormat := "%-" + strconv.Itoa(maxlength) + "s %s\n"
for _, importpath := range imports {
commit, vendored := submodules[importpath]
if vendored {
fmt.Printf(vendoredFormat, importpath, commit)
} else {
fmt.Println(importpath)
}
}
}
return nil
}