erroneousboat-slack-term/main.go

116 lines
1.8 KiB
Go
Raw Normal View History

2016-09-11 17:55:19 +02:00
package main
import (
2016-09-25 22:34:02 +02:00
"flag"
2016-10-09 18:37:00 +02:00
"fmt"
2016-09-25 22:34:02 +02:00
"log"
"os"
2016-09-25 22:34:02 +02:00
"os/user"
"path"
2017-09-23 13:56:45 +02:00
"github.com/erroneousboat/termui"
termbox "github.com/nsf/termbox-go"
2016-09-11 17:55:19 +02:00
2017-09-23 13:56:45 +02:00
"github.com/erroneousboat/slack-term/context"
"github.com/erroneousboat/slack-term/handlers"
2016-09-11 17:55:19 +02:00
)
2016-10-09 18:37:00 +02:00
const (
2018-10-13 18:34:18 +02:00
VERSION = "v0.4.1"
2016-10-30 14:26:12 +01:00
USAGE = `NAME:
2016-10-09 18:37:00 +02:00
slack-term - slack client for your terminal
USAGE:
slack-term -config [path-to-config]
VERSION:
%s
2018-01-27 13:10:59 +01:00
WEBSITE:
https://github.com/erroneousboat/slack-term
2018-01-27 13:10:59 +01:00
2016-10-09 18:37:00 +02:00
GLOBAL OPTIONS:
2018-10-13 18:34:18 +02:00
-config [path-to-config-file]
-token [slack-token]
-debug
-help, -h
2016-10-09 18:37:00 +02:00
`
)
var (
flgConfig string
flgToken string
2017-12-01 23:52:25 +01:00
flgDebug bool
2016-10-09 18:37:00 +02:00
flgUsage bool
)
2016-09-11 17:55:19 +02:00
2016-10-09 18:37:00 +02:00
func init() {
2016-09-25 22:34:02 +02:00
// Get home dir for config file default
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
// Parse flags
2016-10-09 18:37:00 +02:00
flag.StringVar(
&flgConfig,
2016-09-25 22:34:02 +02:00
"config",
path.Join(usr.HomeDir, ".slack-term"),
2016-09-25 22:34:02 +02:00
"location of config file",
)
2016-10-09 18:37:00 +02:00
flag.StringVar(
&flgToken,
"token",
"",
"the slack token",
)
2017-12-01 23:52:25 +01:00
flag.BoolVar(
&flgDebug,
"debug",
false,
"turn on debugging",
)
2016-10-09 18:37:00 +02:00
flag.Usage = func() {
fmt.Printf(USAGE, VERSION)
}
2016-09-25 22:34:02 +02:00
flag.Parse()
2016-10-09 18:37:00 +02:00
}
func main() {
// Start terminal user interface
err := termui.Init()
if err != nil {
log.Fatal(err)
}
defer termui.Close()
2016-09-25 22:34:02 +02:00
// 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
2016-09-25 22:34:02 +02:00
// Create context
2018-10-13 18:34:18 +02:00
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)
}
2016-09-11 17:55:19 +02:00
2019-05-18 12:16:27 +02:00
// Initialize handlers
handlers.Initialize(ctx)
2016-09-11 17:55:19 +02:00
termui.Loop()
}