1package pflag
2
3import (
4	"fmt"
5	"strconv"
6)
7
8// -- uint16 value
9type uint16Value uint16
10
11func newUint16Value(val uint16, p *uint16) *uint16Value {
12	*p = val
13	return (*uint16Value)(p)
14}
15func (i *uint16Value) String() string { return fmt.Sprintf("%d", *i) }
16func (i *uint16Value) Set(s string) error {
17	v, err := strconv.ParseUint(s, 0, 16)
18	*i = uint16Value(v)
19	return err
20}
21
22func (i *uint16Value) Type() string {
23	return "uint16"
24}
25
26// Uint16Var defines a uint flag with specified name, default value, and usage string.
27// The argument p points to a uint variable in which to store the value of the flag.
28func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) {
29	f.VarP(newUint16Value(value, p), name, "", usage)
30}
31
32// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
33func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
34	f.VarP(newUint16Value(value, p), name, shorthand, usage)
35}
36
37// Uint16Var defines a uint flag with specified name, default value, and usage string.
38// The argument p points to a uint  variable in which to store the value of the flag.
39func Uint16Var(p *uint16, name string, value uint16, usage string) {
40	CommandLine.VarP(newUint16Value(value, p), name, "", usage)
41}
42
43// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
44func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
45	CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
46}
47
48// Uint16 defines a uint flag with specified name, default value, and usage string.
49// The return value is the address of a uint  variable that stores the value of the flag.
50func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
51	p := new(uint16)
52	f.Uint16VarP(p, name, "", value, usage)
53	return p
54}
55
56// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
57func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
58	p := new(uint16)
59	f.Uint16VarP(p, name, shorthand, value, usage)
60	return p
61}
62
63// Uint16 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 Uint16(name string, value uint16, usage string) *uint16 {
66	return CommandLine.Uint16P(name, "", value, usage)
67}
68
69// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
70func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
71	return CommandLine.Uint16P(name, shorthand, value, usage)
72}
73