github.com/wtfutil/wtf@v0.43.0/cfg/position_validation.go (about)

     1  package cfg
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/logrusorgru/aurora/v4"
     7  )
     8  
     9  // Common examples of invalid position configuration are:
    10  //
    11  //	position:
    12  //	  top: -3
    13  //	  left: 2
    14  //	  width: 0
    15  //	  height: 1
    16  //
    17  //	position:
    18  //	  top: 3
    19  //	  width: 2
    20  //	  height: 1
    21  //
    22  //	position:
    23  //	  top: 3
    24  //	  # left: 2
    25  //	  width: 2
    26  //	  height: 1
    27  //
    28  //	position:
    29  //	top: 3
    30  //	left: 2
    31  //	width: 2
    32  //	height: 1
    33  type positionValidation struct {
    34  	err    error
    35  	name   string
    36  	intVal int
    37  }
    38  
    39  func (posVal *positionValidation) Error() error {
    40  	return posVal.err
    41  }
    42  
    43  func (posVal *positionValidation) HasError() bool {
    44  	return posVal.err != nil
    45  }
    46  
    47  func (posVal *positionValidation) IntValue() int {
    48  	return posVal.intVal
    49  }
    50  
    51  // String returns the Stringer representation of the positionValidation
    52  func (posVal *positionValidation) String() string {
    53  	return fmt.Sprintf("Invalid value for %s:\t%d", aurora.Yellow(posVal.name), posVal.intVal)
    54  }
    55  
    56  /* -------------------- Unexported Functions -------------------- */
    57  
    58  func newPositionValidation(name string, intVal int, err error) *positionValidation {
    59  	posVal := &positionValidation{
    60  		err:    err,
    61  		name:   name,
    62  		intVal: intVal,
    63  	}
    64  
    65  	return posVal
    66  }