diff --git a/context/context.go b/context/context.go index cd770ae..2a6309b 100644 --- a/context/context.go +++ b/context/context.go @@ -1,8 +1,6 @@ package context import ( - "log" - "github.com/gizak/termui" termbox "github.com/nsf/termbox-go" @@ -28,11 +26,11 @@ type AppContext struct { // CreateAppContext creates an application context which can be passed // and referenced througout the application -func CreateAppContext(flgConfig string) *AppContext { +func CreateAppContext(flgConfig string) (*AppContext, error) { // Load config config, err := config.NewConfig(flgConfig) if err != nil { - log.Fatalf("ERROR: not able to load config file (%s): %s", flgConfig, err) + return nil, err } // Create Service @@ -47,5 +45,5 @@ func CreateAppContext(flgConfig string) *AppContext { View: view, Config: config, Mode: CommandMode, - } + }, nil } diff --git a/main.go b/main.go index 59329f0..8e379c5 100644 --- a/main.go +++ b/main.go @@ -4,11 +4,13 @@ import ( "flag" "fmt" "log" + "os" "os/user" "path" "github.com/erroneousboat/slack-term/context" "github.com/erroneousboat/slack-term/handlers" + termbox "github.com/nsf/termbox-go" "github.com/gizak/termui" ) @@ -74,7 +76,12 @@ func main() { termui.DefaultEvtStream = customEvtStream // Create context - ctx := context.CreateAppContext(flgConfig) + ctx, err := context.CreateAppContext(flgConfig) + if err != nil { + termbox.Close() + log.Println(err) + os.Exit(0) + } // Setup body termui.Body.AddRows(