wi/main.go

47 lines
1.1 KiB
Go
Raw Normal View History

2016-07-21 22:40:19 +03:00
/**
* @file main.go
* @author Mikhail Klementyev jollheef<AT>riseup.net
* @license GNU GPLv3
* @date July, 2016
* @brief Tiny non-interactive cli browser
*/
2016-07-20 01:08:19 +03:00
package main
import (
2016-07-25 18:35:09 +03:00
"github.com/jollheef/wi/commands"
2016-07-22 15:44:12 +03:00
"github.com/jollheef/wi/storage"
2016-07-22 15:43:23 +03:00
2016-07-20 01:08:19 +03:00
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
2016-07-24 11:01:55 +03:00
get = kingpin.Command("get", "Get url")
getUrl = get.Arg("url", "Url").Required().String()
2016-07-25 18:41:12 +03:00
link = kingpin.Command("link", "Get link")
linkNo = link.Arg("no", "Number").Required().Int64()
linkFromHistory = link.Flag("history", "Item from history").Bool()
2016-07-24 11:01:55 +03:00
historyList = kingpin.Command("history", "List history")
historyListItems = historyList.Arg("items", "Amount of items").Int64()
2016-07-24 11:23:24 +03:00
historyListAll = historyList.Flag("all", "Show all items").Bool()
2016-07-20 01:08:19 +03:00
)
2016-07-22 15:43:23 +03:00
func main() {
db, err := storage.OpenDB("/tmp/wi.db")
if err != nil {
panic(err)
}
2016-07-24 11:01:55 +03:00
defer db.Close()
switch kingpin.Parse() {
case "get":
2016-07-25 18:35:09 +03:00
commands.Get(db, *getUrl)
2016-07-24 11:01:55 +03:00
case "link":
2016-07-25 18:41:12 +03:00
commands.Link(db, *linkNo, *linkFromHistory)
2016-07-24 11:01:55 +03:00
case "history":
2016-07-25 18:35:09 +03:00
commands.History(db, *historyListItems, 20, *historyListAll)
2016-07-22 15:43:23 +03:00
}
}