-
Notifications
You must be signed in to change notification settings - Fork 17
/
token.go
46 lines (38 loc) · 893 Bytes
/
token.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
package main
import (
"log"
"github.com/jason0x43/go-alfred"
)
// TokenCommand is a command
type TokenCommand struct{}
// About returns information about this command
func (c TokenCommand) About() alfred.CommandDef {
return alfred.CommandDef{
Keyword: "token",
Description: "Manually enter a Toggl API token",
IsEnabled: config.APIKey == "",
Arg: &alfred.ItemArg{
Keyword: "token",
Mode: alfred.ModeDo,
},
}
}
// Do runs the command
func (c TokenCommand) Do(data string) (string, error) {
btn, token, err := workflow.GetInput("API token", "", false)
if err != nil {
return "", err
}
if btn != "Ok" {
log.Println("User didn't click OK")
return "", nil
}
log.Printf("token: %s", token)
config.APIKey = token
err = alfred.SaveJSON(configFile, &config)
if err != nil {
return "", err
}
workflow.ShowMessage("Token saved!")
return "", nil
}