mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
d46fe9cb6a
Former-commit-id: 2d0a3148379cc650552887358558b05b8efd2545 [formerly b5bbb0e6df504588c406ffea0b7f68ff18b34ff9] [formerly 1cded1417754d12f2ea94246e1e22bc8a7c8631a [formerly d3e04ef2ed
]]
Former-commit-id: be9e181ffd0c1d00666928618237f709760f8f72 [formerly f6f73dc9e043e6b96b190cbfe9011c3e1c7b83a3]
Former-commit-id: 1a016d36925db45aac5786e552ae7c9f7ccde722
82 lines
1.6 KiB
Go
Executable File
82 lines
1.6 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
)
|
|
|
|
var version string
|
|
var pathToData string
|
|
|
|
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
|
|
}
|
|
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",
|
|
},
|
|
cli.StringFlag{
|
|
Name: "port,p",
|
|
Value: "8050",
|
|
Usage: "port to use",
|
|
},
|
|
cli.BoolFlag{
|
|
Name: "debug, d",
|
|
Usage: "turn on debugging",
|
|
},
|
|
}
|
|
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)
|
|
serve(c.GlobalString("port"))
|
|
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
|
|
},
|
|
},
|
|
}
|
|
|
|
app.Run(os.Args)
|
|
|
|
}
|