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