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