-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (39 loc) · 979 Bytes
/
main.go
File metadata and controls
46 lines (39 loc) · 979 Bytes
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
package main
import (
"flag"
"log"
"os"
"golang.org/x/tools/go/packages"
)
const (
codeError = 1
codeUsage = 2
)
func main() {
var excludeTests bool
var buildTags string
flag.BoolVar(&excludeTests, "exclude-tests", false, "do not check test-only package or test executables")
flag.StringVar(&buildTags, "tags", "", "comma-separated list of build tags to include")
log.SetFlags(0) // reset flags to remove time prefix
log.SetPrefix("compiles: ")
flag.Parse()
if len(flag.Args()) == 0 {
log.Print("no packages specified")
os.Exit(codeUsage)
}
cfg := &packages.Config{
BuildFlags: []string{"-tags=" + buildTags},
Mode: packages.LoadAllSyntax | packages.NeedModule,
Tests: !excludeTests,
}
initial, err := packages.Load(cfg, flag.Args()...)
if err != nil {
log.Fatalf("failed to load packages: %v", err)
}
if len(initial) == 0 {
log.Fatalf("no packages found")
}
if packages.PrintErrors(initial) > 0 {
os.Exit(codeError)
}
}