github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/flag/positive_integer.go (about)

     1  package flag
     2  
     3  import (
     4  	"strconv"
     5  
     6  	flags "github.com/jessevdk/go-flags"
     7  )
     8  
     9  type PositiveInteger struct {
    10  	Value int64
    11  }
    12  
    13  func (posInt *PositiveInteger) UnmarshalFlag(rawValue string) error {
    14  	value, err := strconv.ParseInt(rawValue, 10, 0)
    15  	if err != nil {
    16  		return err
    17  	}
    18  
    19  	if value < 1 {
    20  		return &flags.Error{
    21  			Type:    flags.ErrMarshal,
    22  			Message: `Value must be greater than or equal to 1.`,
    23  		}
    24  	}
    25  
    26  	posInt.Value = value
    27  	return nil
    28  }