Implements quick search

This commit is contained in:
dump_stack() 2016-07-30 11:05:50 +03:00
parent a3ee60dcc3
commit 4a4d10c760

29
main.go
View File

@ -9,12 +9,35 @@
package main package main
import ( import (
"strings"
"github.com/jollheef/wi/commands" "github.com/jollheef/wi/commands"
"github.com/jollheef/wi/storage" "github.com/jollheef/wi/storage"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
type searchList []string
func (l *searchList) Set(value string) (err error) {
*l = append(*l, value)
return
}
func (l *searchList) String() (s string) {
return ""
}
func (l *searchList) IsCumulative() bool {
return true
}
func SearchList(settings kingpin.Settings) (target *[]string) {
target = new([]string)
settings.SetValue((*searchList)(target))
return
}
var ( var (
get = kingpin.Command("get", "Get url") get = kingpin.Command("get", "Get url")
getUrl = get.Arg("url", "Url").Required().String() getUrl = get.Arg("url", "Url").Required().String()
@ -26,6 +49,9 @@ var (
historyList = kingpin.Command("history", "List history") historyList = kingpin.Command("history", "List history")
historyListItems = historyList.Arg("items", "Amount of items").Int64() historyListItems = historyList.Arg("items", "Amount of items").Int64()
historyListAll = historyList.Flag("all", "Show all items").Bool() historyListAll = historyList.Flag("all", "Show all items").Bool()
search = kingpin.Command("search", "Search engine (google by default)")
searchArgs = SearchList(search.Arg("string", "String for search"))
) )
func main() { func main() {
@ -42,5 +68,8 @@ func main() {
commands.Link(db, *linkNo, *linkFromHistory) commands.Link(db, *linkNo, *linkFromHistory)
case "history": case "history":
commands.History(db, *historyListItems, 20, *historyListAll) commands.History(db, *historyListItems, 20, *historyListAll)
case "search":
// FIXME: currenlty supports only Google
commands.Get(db, "google.com/search?q="+strings.Join(*searchArgs, "+"))
} }
} }