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