-
Notifications
You must be signed in to change notification settings - Fork 225
/
main.go
112 lines (91 loc) · 1.77 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/OpenPeeDeeP/xdg"
"github.com/erroneousboat/termui"
termbox "github.com/nsf/termbox-go"
"github.com/erroneousboat/slack-term/context"
"github.com/erroneousboat/slack-term/handlers"
)
const (
VERSION = "master"
USAGE = `NAME:
slack-term - slack client for your terminal
USAGE:
slack-term -config [path-to-config]
VERSION:
%s
WEBSITE:
https://github.com/erroneousboat/slack-term
GLOBAL OPTIONS:
-config [path-to-config-file]
-token [slack-token]
-debug
-help, -h
`
)
var (
flgConfig string
flgToken string
flgDebug bool
flgUsage bool
)
func init() {
// Find the default config file
configFile := xdg.New("slack-term", "").QueryConfig("config")
// Parse flags
flag.StringVar(
&flgConfig,
"config",
configFile,
"location of config file",
)
flag.StringVar(
&flgToken,
"token",
"",
"the slack token",
)
flag.BoolVar(
&flgDebug,
"debug",
false,
"turn on debugging",
)
flag.Usage = func() {
fmt.Printf(USAGE, VERSION)
}
flag.Parse()
}
func main() {
// Start terminal user interface
err := termui.Init()
if err != nil {
log.Fatal(err)
}
defer termui.Close()
// Create custom event stream for termui because
// termui's one has data race conditions with its
// event handling. We're circumventing it here until
// it has been fixed.
customEvtStream := &termui.EvtStream{
Handlers: make(map[string]func(termui.Event)),
}
termui.DefaultEvtStream = customEvtStream
// Create context
usage := fmt.Sprintf(USAGE, VERSION)
ctx, err := context.CreateAppContext(
flgConfig, flgToken, flgDebug, VERSION, usage,
)
if err != nil {
termbox.Close()
log.Println(err)
os.Exit(0)
}
// Initialize handlers
handlers.Initialize(ctx)
termui.Loop()
}