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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"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
|
// 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
|
var errStr string
|
||||||
hasErrors := false
|
hasErrors := false
|
||||||
|
|
@ -24,6 +24,7 @@ type WtfApp struct {
|
|||||||
focusTracker FocusTracker
|
focusTracker FocusTracker
|
||||||
isCustomConfig bool
|
isCustomConfig bool
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
|
validator *ModuleValidator
|
||||||
widgets []wtf.Wtfable
|
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.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config)
|
||||||
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
||||||
wtfApp.focusTracker = NewFocusTracker(wtfApp.app, 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.pages.AddPage("grid", wtfApp.display.Grid, true, true)
|
||||||
wtfApp.app.SetRoot(wtfApp.pages, true)
|
wtfApp.app.SetRoot(wtfApp.pages, true)
|
||||||
wtfApp.app.SetInputCapture(wtfApp.keyboardIntercept)
|
wtfApp.app.SetInputCapture(wtfApp.keyboardIntercept)
|
||||||
|
|
||||||
wtf.ValidateWidgets(wtfApp.widgets)
|
wtfApp.validator.Validate(wtfApp.widgets)
|
||||||
|
|
||||||
return &wtfApp
|
return &wtfApp
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user