2017-03-22 05:46:05 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-03-22 06:51:52 +03:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
2017-03-22 05:46:05 +03:00
|
|
|
|
2017-03-22 06:51:52 +03:00
|
|
|
"gopkg.in/urfave/cli.v1"
|
2017-03-22 05:46:05 +03:00
|
|
|
)
|
|
|
|
|
2017-03-22 06:51:52 +03:00
|
|
|
var version string
|
|
|
|
var pathToData string
|
2017-03-22 05:46:05 +03:00
|
|
|
|
2017-03-22 06:51:52 +03:00
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "linkcrawler"
|
|
|
|
app.Usage = "crawl a site for links, or download a list of sites"
|
|
|
|
app.Version = version
|
|
|
|
app.Compiled = time.Now()
|
|
|
|
app.Action = func(c *cli.Context) error {
|
|
|
|
cli.ShowSubcommandHelp(c)
|
|
|
|
return nil
|
2017-03-22 05:46:05 +03:00
|
|
|
}
|
2017-03-22 06:51:52 +03:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "data",
|
|
|
|
Value: "data",
|
|
|
|
Usage: "data folder to use",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "olddata",
|
|
|
|
Value: "",
|
|
|
|
Usage: "data folder for migrating",
|
|
|
|
},
|
2017-03-22 17:26:34 +03:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "port,p",
|
|
|
|
Value: "8050",
|
|
|
|
Usage: "port to use",
|
|
|
|
},
|
2017-03-22 06:51:52 +03:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug, d",
|
|
|
|
Usage: "turn on debugging",
|
|
|
|
},
|
2017-03-22 05:46:05 +03:00
|
|
|
}
|
2017-03-22 06:51:52 +03:00
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "serve",
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Usage: "start a cowyo server",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
pathToData = c.GlobalString("data")
|
|
|
|
os.MkdirAll(pathToData, 0755)
|
2017-03-22 17:26:34 +03:00
|
|
|
serve(c.GlobalString("port"))
|
2017-03-22 06:51:52 +03:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "migrate",
|
|
|
|
Aliases: []string{"m"},
|
|
|
|
Usage: "migrate from the old cowyo",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
pathToData = c.GlobalString("data")
|
|
|
|
pathToOldData := c.GlobalString("olddata")
|
|
|
|
if len(pathToOldData) == 0 {
|
|
|
|
fmt.Printf("You need to specify folder with -olddata")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
os.MkdirAll(pathToData, 0755)
|
|
|
|
if !exists(pathToOldData) {
|
|
|
|
fmt.Printf("Can not find '%s', does it exist?", pathToOldData)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
migrate(pathToOldData, pathToData)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
2017-03-22 05:46:05 +03:00
|
|
|
}
|
2017-03-22 06:06:35 +03:00
|
|
|
|
2017-03-22 06:51:52 +03:00
|
|
|
app.Run(os.Args)
|
2017-03-22 06:06:35 +03:00
|
|
|
|
|
|
|
}
|