1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/main.go
Zack Scholl c66c312fdb Remove serve subcommand
Former-commit-id: d043e461b53d8525268889380e6d307bf1e91ffe [formerly 7148459fedf6847393039077ed1b61c3ad65392f] [formerly f32e700c6e421f094b2c7047fc277050e66d3c70 [formerly 1f6e70028a87b587f42ddd6dd3a240d60cd1e46c [formerly 375979fc19]]]
Former-commit-id: 690c8ae68f8f3f18dd5726d9f30557b251238c71 [formerly 07fe4a8721cd13e277cbb25cd743b1f8ff4c0e82]
Former-commit-id: 2d0761bcb0e6f3b856fb962155b8292e92a231da
Former-commit-id: 15debdf177
2017-03-22 14:14:47 -06:00

80 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 {
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
}
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: "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)
}