-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 845 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"github.com/radeksimko/go-refs/parser"
)
func main() {
var packagePath string
var printFile bool
flag.StringVar(&packagePath, "pkg", "", "full path to package")
flag.BoolVar(&printFile, "printfile", false, "whether to print location alongside package")
flag.Parse()
if packagePath == "" {
log.Fatal("Please provide package path via '-pkg'")
}
if len(flag.Args()) != 1 {
log.Fatal("Please provider path to a file")
}
filePath := flag.Arg(0)
log.Printf("Parsing %s ...", filePath)
f, err := parser.ParseFile(filePath)
if err != nil {
log.Fatal(err)
}
refs, err := parser.FindPackageReferences(f, packagePath)
if err != nil {
log.Fatal(err)
}
for _, ref := range refs {
if printFile {
fmt.Printf("%s:%s\n", filePath, ref)
} else {
fmt.Println(ref)
}
}
}