You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
532 B

4 years ago
package value
import (
"strconv"
"gitoa.ru/go-4devs/console/input/value/flag"
4 years ago
)
type Int struct {
empty
4 years ago
Val []int
4 years ago
Flag flag.Flag
4 years ago
}
func (i *Int) Append(in string) error {
v, err := strconv.Atoi(in)
if err != nil {
return err
}
i.Val = append(i.Val, v)
return nil
}
func (i *Int) Int() int {
if !i.Flag.IsArray() && len(i.Val) == 1 {
return i.Val[0]
}
return 0
}
func (i *Int) Ints() []int {
return i.Val
}
func (i *Int) Any() interface{} {
4 years ago
if i.Flag.IsArray() {
4 years ago
return i.Ints()
}
return i.Int()
}