From 4a4d10c760840202e1cff2b50a5d62c068fe8931 Mon Sep 17 00:00:00 2001 From: Mikhail Klementyev Date: Sat, 30 Jul 2016 11:05:50 +0300 Subject: [PATCH] Implements quick search --- main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/main.go b/main.go index c463fec..fa8645f 100644 --- a/main.go +++ b/main.go @@ -9,12 +9,35 @@ package main import ( + "strings" + "github.com/jollheef/wi/commands" "github.com/jollheef/wi/storage" 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 ( get = kingpin.Command("get", "Get url") getUrl = get.Arg("url", "Url").Required().String() @@ -26,6 +49,9 @@ var ( historyList = kingpin.Command("history", "List history") historyListItems = historyList.Arg("items", "Amount of items").Int64() 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() { @@ -42,5 +68,8 @@ func main() { commands.Link(db, *linkNo, *linkFromHistory) case "history": commands.History(db, *historyListItems, 20, *historyListAll) + case "search": + // FIXME: currenlty supports only Google + commands.Get(db, "google.com/search?q="+strings.Join(*searchArgs, "+")) } }