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