github.com/puellanivis/breton@v0.2.16/lib/gnuflag/int.go (about) 1 package gnuflag 2 3 import ( 4 "strconv" 5 ) 6 7 // -- int Value 8 type intValue int 9 10 func (i *intValue) Set(s string) error { 11 v, err := strconv.ParseInt(s, 0, strconv.IntSize) 12 *i = intValue(v) 13 return err 14 } 15 16 func (i intValue) Get() interface{} { return int(i) } 17 18 func (i intValue) String() string { return strconv.Itoa(int(i)) } 19 20 // Int defines an int flag with specified name, and usage string. 21 // The return value is the address of an int variable that stores the value of the flag. 22 func (f *FlagSet) Int(name string, usage string, options ...Option) *int { 23 p := new(int) 24 if err := f.Var((*intValue)(p), name, usage, options...); err != nil { 25 panic(err) 26 } 27 return p 28 } 29 30 // Int defines an int flag with specified name, and usage string. 31 // The return value is the address of an int variable that stores the value of the flag. 32 func Int(name string, usage string, options ...Option) *int { 33 return CommandLine.Int(name, usage, options...) 34 } 35 36 // -- int64 Value 37 type int64Value int64 38 39 func (i *int64Value) Set(s string) error { 40 v, err := strconv.ParseInt(s, 0, 64) 41 *i = int64Value(v) 42 return err 43 } 44 45 func (i int64Value) Get() interface{} { return int64(i) } 46 47 func (i int64Value) String() string { return strconv.FormatInt(int64(i), 10) } 48 49 // Int64 defines an int64 flag with specified name, and usage string. 50 // The return value is the address of an int64 variable that stores the value of the flag. 51 func (f *FlagSet) Int64(name string, usage string, options ...Option) *int64 { 52 p := new(int64) 53 if err := f.Var((*int64Value)(p), name, usage, options...); err != nil { 54 panic(err) 55 } 56 return p 57 } 58 59 // Int64 defines an int64 flag with specified name, and usage string. 60 // The return value is the address of an int64 variable that stores the value of the flag. 61 func Int64(name string, usage string, options ...Option) *int64 { 62 return CommandLine.Int64(name, usage, options...) 63 }