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:
parent
b790b27000
commit
82c89668a0
19
app/error_messages.go
Normal file
19
app/error_messages.go
Normal 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())
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user