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.
32 lines
741 B
32 lines
741 B
2 years ago
|
package variable
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strconv"
|
||
|
|
||
|
"gitoa.ru/go-4devs/console/input/flag"
|
||
|
"gitoa.ru/go-4devs/console/input/value"
|
||
|
)
|
||
|
|
||
|
func Int64(name, description string, opts ...Option) Variable {
|
||
|
return String(name, description, append(opts, WithParse(CreateInt64, AppendInt64), Value(flag.Int64))...)
|
||
|
}
|
||
|
|
||
|
func CreateInt64(in string) (value.Value, error) {
|
||
|
out, err := strconv.ParseInt(in, 10, 64)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("create int64:%w", err)
|
||
|
}
|
||
|
|
||
|
return value.NewInt64(out), nil
|
||
|
}
|
||
|
|
||
|
func AppendInt64(old value.Value, in string) (value.Value, error) {
|
||
|
out, err := strconv.ParseInt(in, 10, 64)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("append int64:%w", err)
|
||
|
}
|
||
|
|
||
|
return value.NewInt64s(append(old.Int64s(), out)), nil
|
||
|
}
|