forked from flaccid/crawlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (52 loc) · 1.05 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"os"
"github.com/flaccid/crawlc/crawl"
"github.com/urfave/cli"
log "github.com/Sirupsen/logrus"
)
var (
VERSION = "v0.0.0-dev"
)
func beforeApp(c *cli.Context) error {
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
}
if len(c.Args().Get(0)) < 1 {
log.Fatal("please provide an url to crawl")
}
return nil
}
func main() {
app := cli.NewApp()
app.Name = "crawlc"
app.Version = VERSION
app.Usage = "a website crawler, frontend to gocrawl"
app.Action = start
app.Before = beforeApp
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "external,e",
Usage: "crawl external urls",
},
cli.IntFlag{
Name: "crawl-delay,d",
Usage: "crawl delay in seconds",
Value: 1,
},
cli.IntFlag{
Name: "max-visits,m",
Usage: "maximum number of visits",
Value: 100000,
},
cli.BoolFlag{
Name: "debug,D",
Usage: "run in debug mode",
},
}
app.Run(os.Args)
}
func start(c *cli.Context) error {
crawl.Crawl(c.Args().Get(0), c.Bool("external"), c.Int("crawl-delay"), c.Int("max-visits"))
return nil
}