-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
94 lines (73 loc) · 1.76 KB
/
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
92
93
94
package main
import (
"fmt"
"github.com/deanishe/awgo"
"github.com/deanishe/awgo/update"
"gopkg.in/alecthomas/kingpin.v2"
)
// Defaults for Kingpin flags
const (
defaultMaxResults = "100"
)
// Icons
var (
IconDefault = &aw.Icon{Value: "icon.png"}
IconUpdate = &aw.Icon{Value: "icons/update-available.png"}
)
var (
// Kingpin and script options
app *kingpin.Application
// Application commands
searchTopicsCmd *kingpin.CmdClause
searchListsCmd *kingpin.CmdClause
updateCmd *kingpin.CmdClause
testCmd *kingpin.CmdClause
// Script options (populated by Kingpin application)
query string
repo = "nikitavoloboev/alfred-learn-anything"
// Workflow stuff
wf *aw.Workflow
)
// Sets up kingpin commands
func init() {
wf = aw.New(update.GitHub(repo), aw.HelpURL(repo+"/issues"))
app = kingpin.New("learn anything", "Search Learn Anything.")
updateCmd = app.Command("update", "Check for new version.")
searchTopicsCmd = app.Command("topics", "Search Learn Anything topics.")
searchListsCmd = app.Command("lists", "Search curated lists.")
for _, cmd := range []*kingpin.CmdClause{
searchTopicsCmd, searchListsCmd,
} {
cmd.Flag("query", "Search query.").Short('q').StringVar(&query)
}
}
func run() {
var err error
cmd, err := app.Parse(wf.Args())
if err != nil {
wf.FatalError(err)
}
switch cmd {
case searchTopicsCmd.FullCommand():
err = doSearchTopics()
case searchListsCmd.FullCommand():
err = doSearchLists()
case updateCmd.FullCommand():
err = doUpdate()
default:
err = fmt.Errorf("Uknown command: %s", cmd)
}
// Check for update
if err == nil && cmd != updateCmd.FullCommand() {
err = checkForUpdate()
}
if err != nil {
wf.FatalError(err)
}
}
func doTest() error {
return nil
}
func main() {
wf.Run(run)
}