1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move the ModuleValidator from /wtf to /app

This commit is contained in:
Chris Cummer 2019-07-28 06:30:18 -07:00
parent b790b27000
commit 82c89668a0
3 changed files with 33 additions and 4 deletions

19
app/error_messages.go Normal file
View File

@ -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())
}

View File

@ -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

View File

@ -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
}