| 1 |
package pflag |
| 2 |
|
| 3 |
import "strconv" |
| 4 |
|
| 5 |
// -- uint16 value |
| 6 |
type uint16Value uint16 |
| 7 |
|
| 8 |
func newUint16Value(val uint16, p *uint16) *uint16Value { |
| 9 |
*p = val |
| 10 |
return (*uint16Value)(p) |
| 11 |
} |
| 12 |
|
| 13 |
func (i *uint16Value) Set(s string) error { |
| 14 |
v, err := strconv.ParseUint(s, 0, 16) |
| 15 |
*i = uint16Value(v) |
| 16 |
return err |
| 17 |
} |
| 18 |
|
| 19 |
func (i *uint16Value) Type() string { |
| 20 |
return "uint16" |
| 21 |
} |
| 22 |
|
| 23 |
func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } |
| 24 |
|
| 25 |
func uint16Conv(sval string) (interface{}, error) { |
| 26 |
v, err := strconv.ParseUint(sval, 0, 16) |
| 27 |
if err != nil { |
| 28 |
return 0, err |
| 29 |
} |
| 30 |
return uint16(v), nil |
| 31 |
} |
| 32 |
|
| 33 |
// GetUint16 return the uint16 value of a flag with the given name |
| 34 |
func (f *FlagSet) GetUint16(name string) (uint16, error) { |
| 35 |
val, err := f.getFlagType(name, "uint16", uint16Conv) |
| 36 |
if err != nil { |
| 37 |
return 0, err |
| 38 |
} |
| 39 |
return val.(uint16), nil |
| 40 |
} |
| 41 |
|
| 42 |
// Uint16Var defines a uint flag with specified name, default value, and usage string. |
| 43 |
// The argument p points to a uint variable in which to store the value of the flag. |
| 44 |
func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { |
| 45 |
f.VarP(newUint16Value(value, p), name, "", usage) |
| 46 |
} |
| 47 |
|
| 48 |
// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. |
| 49 |
func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { |
| 50 |
f.VarP(newUint16Value(value, p), name, shorthand, usage) |
| 51 |
} |
| 52 |
|
| 53 |
// Uint16Var defines a uint flag with specified name, default value, and usage string. |
| 54 |
// The argument p points to a uint variable in which to store the value of the flag. |
| 55 |
func Uint16Var(p *uint16, name string, value uint16, usage string) { |
| 56 |
CommandLine.VarP(newUint16Value(value, p), name, "", usage) |
| 57 |
} |
| 58 |
|
| 59 |
// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. |
| 60 |
func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { |
| 61 |
CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) |
| 62 |
} |
| 63 |
|
| 64 |
// Uint16 defines a uint flag with specified name, default value, and usage string. |
| 65 |
// The return value is the address of a uint variable that stores the value of the flag. |
| 66 |
func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { |
| 67 |
p := new(uint16) |
| 68 |
f.Uint16VarP(p, name, "", value, usage) |
| 69 |
return p |
| 70 |
} |
| 71 |
|
| 72 |
// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. |
| 73 |
func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { |
| 74 |
p := new(uint16) |
| 75 |
f.Uint16VarP(p, name, shorthand, value, usage) |
| 76 |
return p |
| 77 |
} |
| 78 |
|
| 79 |
// Uint16 defines a uint flag with specified name, default value, and usage string. |
| 80 |
// The return value is the address of a uint variable that stores the value of the flag. |
| 81 |
func Uint16(name string, value uint16, usage string) *uint16 { |
| 82 |
return CommandLine.Uint16P(name, "", value, usage) |
| 83 |
} |
| 84 |
|
| 85 |
// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. |
| 86 |
func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { |
| 87 |
return CommandLine.Uint16P(name, shorthand, value, usage) |
| 88 |
} |