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.
31 lines
744 B
31 lines
744 B
package variable
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"gitoa.ru/go-4devs/console/input/flag"
|
|
"gitoa.ru/go-4devs/console/input/value"
|
|
)
|
|
|
|
func Uint(name, description string, opts ...Option) Variable {
|
|
return String(name, description, append(opts, WithParse(CreateUint, AppendUint), Value(flag.Uint))...)
|
|
}
|
|
|
|
func CreateUint(in string) (value.Value, error) {
|
|
out, err := strconv.ParseUint(in, 10, 64)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create uint:%w", err)
|
|
}
|
|
|
|
return value.NewUint(uint(out)), nil
|
|
}
|
|
|
|
func AppendUint(old value.Value, in string) (value.Value, error) {
|
|
out, err := strconv.ParseUint(in, 10, 64)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("append uint:%w", err)
|
|
}
|
|
|
|
return value.NewUints(append(old.Uints(), uint(out))), nil
|
|
}
|
|
|