1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/main.go
Zack Scholl 6347038563 Cowyo works as a single binary now
Former-commit-id: e3c11510f61564a5f8c6a53d9d9bd768c5fa0f17 [formerly 8c3e635c3cfd2f00acbe4fe4c89b5c9921c3a4ba] [formerly ed287ec86da7ff501a972dcb68f9a0045dcb3798 [formerly b2ea068629093bbeebca0be37f463701117a5d1b [formerly 3f3ee6c9fa]]]
Former-commit-id: 049fac69946d4e4a7866d28afa0999bac8457840 [formerly 4451a7e8d278d70f1547f4ade77df8f9ef76b0d3]
Former-commit-id: 3a8a4d9ab222d9d23ebf6981e0553a28a123a08f
Former-commit-id: 70616e9d31
2017-03-22 13:19:00 -06:00

89 lines
1.8 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 {
if !c.GlobalBool("debug") {
turnOffDebugger()
}
pathToData = c.GlobalString("data")
os.MkdirAll(pathToData, 0755)
fmt.Printf("\nRunning CowYo at http://%s:%s\n\n", GetLocalIP(), c.GlobalString("port"))
serve(c.GlobalString("port"))
return nil
},
},
{
Name: "migrate",
Aliases: []string{"m"},
Usage: "migrate from the old cowyo",
Action: func(c *cli.Context) error {
if !c.GlobalBool("debug") {
turnOffDebugger()
}
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)
}