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