From fccd062b85bc84a4550972bb4256244381076b97 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 28 Jul 2019 06:30:18 -0700 Subject: [PATCH] Move the ModuleValidator from /wtf to /app --- app/error_messages.go | 19 +++++++++++++++++++ .../module_validator.go | 14 +++++++++++--- app/wtf_app.go | 4 +++- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 app/error_messages.go rename wtf/widget_validation.go => app/module_validator.go (72%) diff --git a/app/error_messages.go b/app/error_messages.go new file mode 100644 index 00000000..76f0e602 --- /dev/null +++ b/app/error_messages.go @@ -0,0 +1,19 @@ +package app + +// This file contains the error messages that get written to the terminal when +// something goes wrong with the configuration process. +// +// As a general rule, if one of these has to be shown the app should then die +// via os.Exit(1) + +import ( + "fmt" + + "github.com/logrusorgru/aurora" +) + +/* -------------------- Unexported Functions -------------------- */ + +func displayError(err error) { + fmt.Printf("%s %s\n\n", aurora.Red("Error:"), err.Error()) +} diff --git a/wtf/widget_validation.go b/app/module_validator.go similarity index 72% rename from wtf/widget_validation.go rename to app/module_validator.go index 36f03123..36ba6275 100644 --- a/wtf/widget_validation.go +++ b/app/module_validator.go @@ -1,15 +1,23 @@ -package wtf +package app import ( "fmt" "os" "github.com/logrusorgru/aurora" + "github.com/wtfutil/wtf/wtf" ) -// ValidateWidgets rolls through all the enabled widgets and looks for configuration errors. +type ModuleValidator struct{} + +func NewModuleValidator() *ModuleValidator { + val := &ModuleValidator{} + return val +} + +// Validate rolls through all the enabled widgets and looks for configuration errors. // If it finds any it stringifies them, writes them to the console, and kills the app gracefully -func ValidateWidgets(widgets []Wtfable) { +func (val *ModuleValidator) Validate(widgets []wtf.Wtfable) { var errStr string hasErrors := false diff --git a/app/wtf_app.go b/app/wtf_app.go index dca52b19..99235c56 100644 --- a/app/wtf_app.go +++ b/app/wtf_app.go @@ -24,6 +24,7 @@ type WtfApp struct { focusTracker FocusTracker isCustomConfig bool pages *tview.Pages + validator *ModuleValidator widgets []wtf.Wtfable } @@ -40,12 +41,13 @@ func NewWtfApp(app *tview.Application, config *config.Config, configFilePath str wtfApp.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config) wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config) wtfApp.focusTracker = NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config) + wtfApp.validator = NewModuleValidator() wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true) wtfApp.app.SetRoot(wtfApp.pages, true) wtfApp.app.SetInputCapture(wtfApp.keyboardIntercept) - wtf.ValidateWidgets(wtfApp.widgets) + wtfApp.validator.Validate(wtfApp.widgets) return &wtfApp }