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:
@@ -1,51 +0,0 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
// ValidateWidgets 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) {
|
||||
var errStr string
|
||||
hasErrors := false
|
||||
|
||||
for _, widget := range widgets {
|
||||
var widgetErrStr string
|
||||
|
||||
for _, val := range widget.CommonSettings().Validations() {
|
||||
if val.HasError() {
|
||||
hasErrors = true
|
||||
widgetErrStr += fmt.Sprintf(" - %s\t%s %v\n", val, aurora.Red("Error:"), val.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if widgetErrStr != "" {
|
||||
errStr += fmt.Sprintf(
|
||||
"%s\n",
|
||||
fmt.Sprintf(
|
||||
"%s in %s configuration",
|
||||
aurora.Red("Errors"),
|
||||
aurora.Yellow(
|
||||
fmt.Sprintf(
|
||||
"%s.position",
|
||||
widget.Name(),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
errStr += widgetErrStr + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
if hasErrors {
|
||||
fmt.Println()
|
||||
fmt.Printf(errStr)
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user