-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
56 lines (50 loc) · 954 Bytes
/
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
package main
import (
"os"
"github.com/codegangsta/cli"
"github.com/spf13/viper"
"github.com/uetchy/go-qiita/qiita"
"golang.org/x/oauth2"
)
const (
bundleID = "co.randompaper.alfred-qiita-workflow"
version = "2.1.0"
)
func newQiitaClient() (*qiita.Client, error) {
loadConfig()
var client *qiita.Client
if accessToken := viper.GetString("accessToken"); accessToken != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: accessToken},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client = qiita.NewClient(tc)
} else {
client = qiita.NewClient(nil)
}
return client, nil
}
func main() {
app := cli.NewApp()
app.Name = "alfred-qiita"
app.Version = version
app.Commands = []cli.Command{
{
Name: "setup",
Action: cmdSetup,
},
{
Name: "search",
Action: cmdSearch,
},
{
Name: "stocks",
Action: cmdStocks,
},
{
Name: "my",
Action: cmdMy,
},
}
app.Run(os.Args)
}