/
main.go
37 lines (33 loc) · 867 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
package main
import (
"flag"
"github.com/RobinUS2/godephunter/service"
"time"
)
func main() {
svc := service.New()
if svc == nil {
panic("nil")
}
var target string
flag.StringVar(&target, "find", "", "the name of the dep to locate (e.g. github.com/Route42/golang-commons/httpclient@v0.0.0-20210615)")
flag.Parse()
var bodyChan = make(chan string, 1)
go func() {
bodyChan <- svc.ReadStdIn()
}()
select {
case body := <-bodyChan:
opts := svc.NewScanOpts()
opts.Target = service.Target(target)
res, err := svc.Scan(body, opts)
if err != nil {
svc.Log().Error(err)
return
}
svc.Log().Info(res.String())
case <-time.After(5 * time.Second):
// timeout
svc.Log().Error(`failed to read from stdin. use as:` + "\n" + `go mod graph | godephunter --find="github.com/Route42/golang-commons/httpclient@v0.0.0-20210615"` + "\n\n")
}
}