forked from westerlind/alfred-raindrop-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraindrop_main.go
91 lines (83 loc) · 2.6 KB
/
raindrop_main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"flag"
"os"
aw "github.com/deanishe/awgo"
"github.com/gregjones/httpcache/diskcache"
)
var wf *aw.Workflow
var httpDiskCache *diskcache.Cache
func init() {
wf = aw.New()
httpDiskCache = init_cache(wf.CacheDir() + "/httpcache")
}
func run() {
// Handle command line arguments
f := os.Args[1]
var query string
var variant string
var bookmark_url string
var bookmark_title string
var firefox_json string
var message string
var title string
var tags string
flagSet := flag.NewFlagSet("", flag.ExitOnError)
flagSet.StringVar(&query, "query", "", "Search Query")
flagSet.StringVar(&variant, "variant", "standard", "Variant of the main selected function")
flagSet.StringVar(&bookmark_url, "bookmark_url", "", "URL of bookmark that should be added")
flagSet.StringVar(&bookmark_title, "bookmark_title", "", "Title of bookmark that should be added")
flagSet.StringVar(&firefox_json, "firefox_json", "", "Firefox json")
flagSet.StringVar(&message, "message", "", "Message, for example forwarded error message to handle")
flagSet.StringVar(&title, "title", "", "Bookmark title")
flagSet.StringVar(&tags, "tags", "", "Comma separated bookmark tags")
flagSet.Parse(os.Args[2:])
descr_in_list := false
favs_first := true
full_collection_paths := false
if wf.Config.Get("description_in_boomark_listing", "0") == "1" {
descr_in_list = true
}
if wf.Config.Get("favourites_first", "true") == "0" {
favs_first = false
}
if wf.Config.Get("subcollections_as_full_paths", "0") == "1" {
full_collection_paths = true
}
// Select function
if f == "search" {
search(variant, query, wf.Config.Get("collection_info", ""), wf.Config.Get("from", ""), descr_in_list, favs_first)
}
if f == "browse" {
browse(query, full_collection_paths)
}
if f == "select_collection" {
select_collection(query, bookmark_url, bookmark_title, firefox_json, full_collection_paths)
}
if f == "firefox_error" {
firefox_error(message)
}
if f == "set_title" {
set_title(title)
}
if f == "set_tags" {
set_tags(tags)
}
wf.SendFeedback()
}
func main() {
if os.Args[1] == "authserver" {
// If the first argument is "authserver", start the authserver
authserver()
} else if os.Args[1] == "save_bookmark" {
// If the first argument is "save_bookmark", then go and save the bookmark
var tags string
flagSet := flag.NewFlagSet("", flag.ExitOnError)
flagSet.StringVar(&tags, "tags", "", "Comma separated bookmark tags")
flagSet.Parse(os.Args[2:])
save_bookmark(tags)
} else {
// Else, run normally, meaning that we will run with the assumption that we will output json for rendering in Alfred
wf.Run(run)
}
}