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