-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcheck.go
More file actions
64 lines (53 loc) · 980 Bytes
/
pcheck.go
File metadata and controls
64 lines (53 loc) · 980 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"go/build"
"os"
)
// Command line args
var args []string
// Working directory
var pwd = ""
// Output streams
var (
stdout = os.Stdout
stderr = os.Stderr
)
// Build context
var buildContext = build.Default
// Configuration
var config struct {
includeTests bool
}
func init() {
// Parse command line flags
flag.BoolVar(&config.includeTests, "tests", false, "Include test packages?")
flag.Parse()
// Parse command line args
args = flag.Args()
// Get pwd
var err error
pwd, err = os.Getwd()
if err != nil {
fmt.Fprintf(stderr, "Error: %s\n", err)
os.Exit(1)
}
}
func main() {
fmt.Fprintf(stdout, "Include tests? %+v\n", config.includeTests)
bp, err := buildContext.Import(args[0], pwd, 0)
if err != nil {
fmt.Println(err)
return
}
// fmt.Printf("%+v\n", bp)
for _, imp := range bp.Imports {
fmt.Println(imp)
}
if config.includeTests {
for _, imp := range bp.TestImports {
fmt.Println(imp)
}
}
}