Path: blob/main/vendor/github.com/spf13/pflag/uint8.go
2875 views
package pflag12import "strconv"34// -- uint8 Value5type uint8Value uint867func newUint8Value(val uint8, p *uint8) *uint8Value {8*p = val9return (*uint8Value)(p)10}1112func (i *uint8Value) Set(s string) error {13v, err := strconv.ParseUint(s, 0, 8)14*i = uint8Value(v)15return err16}1718func (i *uint8Value) Type() string {19return "uint8"20}2122func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) }2324func uint8Conv(sval string) (interface{}, error) {25v, err := strconv.ParseUint(sval, 0, 8)26if err != nil {27return 0, err28}29return uint8(v), nil30}3132// GetUint8 return the uint8 value of a flag with the given name33func (f *FlagSet) GetUint8(name string) (uint8, error) {34val, err := f.getFlagType(name, "uint8", uint8Conv)35if err != nil {36return 0, err37}38return val.(uint8), nil39}4041// Uint8Var defines a uint8 flag with specified name, default value, and usage string.42// The argument p points to a uint8 variable in which to store the value of the flag.43func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {44f.VarP(newUint8Value(value, p), name, "", usage)45}4647// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.48func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {49f.VarP(newUint8Value(value, p), name, shorthand, usage)50}5152// Uint8Var defines a uint8 flag with specified name, default value, and usage string.53// The argument p points to a uint8 variable in which to store the value of the flag.54func Uint8Var(p *uint8, name string, value uint8, usage string) {55CommandLine.VarP(newUint8Value(value, p), name, "", usage)56}5758// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.59func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {60CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)61}6263// Uint8 defines a uint8 flag with specified name, default value, and usage string.64// The return value is the address of a uint8 variable that stores the value of the flag.65func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {66p := new(uint8)67f.Uint8VarP(p, name, "", value, usage)68return p69}7071// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.72func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {73p := new(uint8)74f.Uint8VarP(p, name, shorthand, value, usage)75return p76}7778// Uint8 defines a uint8 flag with specified name, default value, and usage string.79// The return value is the address of a uint8 variable that stores the value of the flag.80func Uint8(name string, value uint8, usage string) *uint8 {81return CommandLine.Uint8P(name, "", value, usage)82}8384// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.85func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {86return CommandLine.Uint8P(name, shorthand, value, usage)87}888990