mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package cfg
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
)
|
|
|
|
// Common examples of invalid position configuration are:
|
|
//
|
|
// position:
|
|
// top: -3
|
|
// left: 2
|
|
// width: 0
|
|
// height: 1
|
|
//
|
|
// position:
|
|
// top: 3
|
|
// width: 2
|
|
// height: 1
|
|
//
|
|
// position:
|
|
// top: 3
|
|
// # left: 2
|
|
// width: 2
|
|
// height: 1
|
|
//
|
|
// position:
|
|
// top: 3
|
|
// left: 2
|
|
// width: 2
|
|
// height: 1
|
|
//
|
|
type positionValidation struct {
|
|
err error
|
|
name string
|
|
intVal int
|
|
}
|
|
|
|
func (posVal *positionValidation) Error() error {
|
|
return posVal.err
|
|
}
|
|
|
|
func (posVal *positionValidation) HasError() bool {
|
|
return posVal.err != nil
|
|
}
|
|
|
|
func (posVal *positionValidation) IntValue() int {
|
|
return posVal.intVal
|
|
}
|
|
|
|
// String returns the Stringer representation of the positionValidation
|
|
func (posVal *positionValidation) String() string {
|
|
return fmt.Sprintf("Invalid value for %s:\t%d", aurora.Yellow(posVal.name), posVal.intVal)
|
|
}
|
|
|
|
func newPositionValidation(name string, intVal int, err error) *positionValidation {
|
|
posVal := &positionValidation{
|
|
err: err,
|
|
name: name,
|
|
intVal: intVal,
|
|
}
|
|
|
|
return posVal
|
|
}
|