aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2017-02-20 11:28:43 -0800
committerAdam Mathes <adam@trenchant.org>2017-02-20 11:28:43 -0800
commit63923e5de3fea586f892602e6d4b74a49bcc6940 (patch)
treebb5eb2c7452ff51f518e96b980fc6914fff69cf7 /main.go
parent38a504c2afecb5ec76358a16a03a6cf0a61d0b84 (diff)
downloadneko-63923e5de3fea586f892602e6d4b74a49bcc6940.tar.gz
neko-63923e5de3fea586f892602e6d4b74a49bcc6940.tar.bz2
neko-63923e5de3fea586f892602e6d4b74a49bcc6940.zip
switch to single binary (neko) with standard flags. update config file to use nicer names
Diffstat (limited to 'main.go')
-rw-r--r--main.go63
1 files changed, 24 insertions, 39 deletions
diff --git a/main.go b/main.go
index 20a1262..fdf4e4b 100644
--- a/main.go
+++ b/main.go
@@ -1,57 +1,42 @@
package main
import (
- "fmt"
+ "flag"
"adammathes.com/neko/config"
- "adammathes.com/neko/crawler"
- "adammathes.com/neko/importer"
+ "adammathes.com/neko/crawler"
"adammathes.com/neko/models"
"adammathes.com/neko/models/feed"
"adammathes.com/neko/web"
"log"
- "os"
)
func main() {
- // TODO: change this
- config.Read("./config.json")
+ var serve, update bool
+ var configFile, newFeed string
+
+ flag.StringVar(&configFile, "c", "config.json", "`configuration` file")
+ flag.BoolVar(&update, "update", false, "update items by fetching feeds")
+ flag.BoolVar(&serve, "serve", false, "run http server")
+ flag.StringVar(&newFeed, "add", "", "add feed `http://example.com/rss.xml`")
+ flag.Parse()
+
+ if !update && !serve {
+ flag.Usage()
+ return
+ }
+
+ config.Read(configFile)
models.InitDB(config.Config.DBServer)
- if len(os.Args) < 2 {
- fmt.Printf("usage: neko [web|addfeed|crawl]\n")
- fmt.Printf("addfeed <url> -- add a new feed from <url>\n")
- return
+
+ if newFeed != "" {
+ feed.NewFeed(newFeed)
}
- cmd := os.Args[1]
- switch cmd {
- case "web":
+ if serve {
log.Printf("starting web server at %s", config.Config.WebServer)
web.Serve()
- case "addfeed":
- addFeed()
- case "crawl":
- crawl()
- case "import":
- importLegacy()
- default:
- panic("not a valid command")
}
-}
-
-func addFeed() {
- if len(os.Args) < 2 {
- log.Fatal("need a valid url")
- }
- url := os.Args[2]
- feed.NewFeed(url)
-}
-
-func importLegacy() {
- json_file := os.Args[2]
- log.Printf("importing json file from: %s", json_file)
- importer.ImportJSON(json_file)
-}
-
-func crawl() {
- crawler.Crawl()
+ if update {
+ crawler.Crawl()
+ }
}