Kent Hagerman | e566c2e | 2019-06-03 17:56:42 -0400 | [diff] [blame] | 1 | package pflag |
| 2 | |
| 3 | import "strconv" |
| 4 | |
| 5 | // -- int64 Value |
| 6 | type int64Value int64 |
| 7 | |
| 8 | func newInt64Value(val int64, p *int64) *int64Value { |
| 9 | *p = val |
| 10 | return (*int64Value)(p) |
| 11 | } |
| 12 | |
| 13 | func (i *int64Value) Set(s string) error { |
| 14 | v, err := strconv.ParseInt(s, 0, 64) |
| 15 | *i = int64Value(v) |
| 16 | return err |
| 17 | } |
| 18 | |
| 19 | func (i *int64Value) Type() string { |
| 20 | return "int64" |
| 21 | } |
| 22 | |
| 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } |
| 24 | |
| 25 | func int64Conv(sval string) (interface{}, error) { |
| 26 | return strconv.ParseInt(sval, 0, 64) |
| 27 | } |
| 28 | |
| 29 | // GetInt64 return the int64 value of a flag with the given name |
| 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { |
| 31 | val, err := f.getFlagType(name, "int64", int64Conv) |
| 32 | if err != nil { |
| 33 | return 0, err |
| 34 | } |
| 35 | return val.(int64), nil |
| 36 | } |
| 37 | |
| 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. |
| 39 | // The argument p points to an int64 variable in which to store the value of the flag. |
| 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { |
| 41 | f.VarP(newInt64Value(value, p), name, "", usage) |
| 42 | } |
| 43 | |
| 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. |
| 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { |
| 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) |
| 47 | } |
| 48 | |
| 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. |
| 50 | // The argument p points to an int64 variable in which to store the value of the flag. |
| 51 | func Int64Var(p *int64, name string, value int64, usage string) { |
| 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) |
| 53 | } |
| 54 | |
| 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. |
| 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { |
| 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) |
| 58 | } |
| 59 | |
| 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. |
| 61 | // The return value is the address of an int64 variable that stores the value of the flag. |
| 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { |
| 63 | p := new(int64) |
| 64 | f.Int64VarP(p, name, "", value, usage) |
| 65 | return p |
| 66 | } |
| 67 | |
| 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. |
| 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { |
| 70 | p := new(int64) |
| 71 | f.Int64VarP(p, name, shorthand, value, usage) |
| 72 | return p |
| 73 | } |
| 74 | |
| 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. |
| 76 | // The return value is the address of an int64 variable that stores the value of the flag. |
| 77 | func Int64(name string, value int64, usage string) *int64 { |
| 78 | return CommandLine.Int64P(name, "", value, usage) |
| 79 | } |
| 80 | |
| 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. |
| 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { |
| 83 | return CommandLine.Int64P(name, shorthand, value, usage) |
| 84 | } |