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