Use commands instead of flags

This commit is contained in:
Mikhail Klementyev 2016-07-24 11:01:55 +03:00
parent 1f6e2db2f2
commit 94c6cd800f

24
main.go
View File

@ -27,8 +27,14 @@ import (
) )
var ( var (
arg_url = kingpin.Flag("url", "Url").String() get = kingpin.Command("get", "Get url")
arg_link = kingpin.Flag("link", "Link").Int64() getUrl = get.Arg("url", "Url").Required().String()
link = kingpin.Command("link", "Get link")
linkNo = link.Arg("no", "Number").Required().Int64()
historyList = kingpin.Command("history", "List history")
historyListItems = historyList.Arg("items", "Amount of items").Int64()
) )
func parseLink(db *sql.DB, oldPage, value string, req *http.Request) (htmlPage string, err error) { func parseLink(db *sql.DB, oldPage, value string, req *http.Request) (htmlPage string, err error) {
@ -141,12 +147,14 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer db.Close()
kingpin.Parse() switch kingpin.Parse() {
case "get":
if *arg_url != "" { cmd_url(db, *getUrl)
cmd_url(db, *arg_url) case "link":
} else if *arg_link != 0 { cmd_link(db, *linkNo)
cmd_link(db, *arg_link) case "history":
fmt.Println("not implemented")
} }
} }