forked from spf13/pflag
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
int16.go
130 lines (106 loc) · 4.7 KB
/
int16.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package pflag
import "strconv"
// -- int16 Value
type int16Value int16
func newInt16Value(val int16, p *int16) *int16Value {
*p = val
return (*int16Value)(p)
}
func (i *int16Value) Set(s string) error {
v, err := strconv.ParseInt(s, 0, 16)
*i = int16Value(v)
return err
}
func (i *int16Value) Type() string {
return "int16"
}
func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) }
func int16Conv(sval string) (interface{}, error) {
v, err := strconv.ParseInt(sval, 0, 16)
if err != nil {
return 0, err
}
return int16(v), nil
}
// GetInt16 returns the int16 value of a flag with the given name
func (f *FlagSet) GetInt16(name string) (int16, error) {
val, err := f.getFlagType(name, "int16", int16Conv)
if err != nil {
return 0, err
}
return val.(int16), nil
}
// Int16Var defines an int16 flag with specified name, default value, and usage string.
// The argument p points to an int16 variable in which to store the value of the flag.
func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) {
f.Int16VarP(p, name, "", value, usage)
}
// Int16VarN like Int16VarP, but adds the name as shorthand (non-posix).
func (f *FlagSet) Int16VarN(p *int16, name, shorthand string, value int16, usage string) {
f.VarN(newInt16Value(value, p), name, shorthand, usage)
}
// Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) {
f.VarP(newInt16Value(value, p), name, shorthand, usage)
}
// Int16VarS is like Int16Var, but accepts a shorthand letter that can be used after a single dash, alone.
func (f *FlagSet) Int16VarS(p *int16, name, shorthand string, value int16, usage string) {
f.VarS(newInt16Value(value, p), name, shorthand, usage)
}
// Int16Var defines an int16 flag with specified name, default value, and usage string.
// The argument p points to an int16 variable in which to store the value of the flag.
func Int16Var(p *int16, name string, value int16, usage string) {
CommandLine.Int16Var(p, name, value, usage)
}
// Int16VarN like Int16VarP, but adds the name as shorthand (non-posix).
func Int16VarN(p *int16, name, shorthand string, value int16, usage string) {
CommandLine.Int16VarN(p, name, shorthand, value, usage)
}
// Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func Int16VarP(p *int16, name, shorthand string, value int16, usage string) {
CommandLine.Int16VarP(p, name, shorthand, value, usage)
}
// Int16VarS is like Int16Var, but accepts a shorthand letter that can be used after a single dash, alone.
func Int16VarS(p *int16, name, shorthand string, value int16, usage string) {
CommandLine.Int16VarS(p, name, shorthand, value, usage)
}
// Int16 defines an int16 flag with specified name, default value, and usage string.
// The return value is the address of an int16 variable that stores the value of the flag.
func (f *FlagSet) Int16(name string, value int16, usage string) *int16 {
return f.Int16P(name, "", value, usage)
}
// Int16N like Int16P, but adds the name as shorthand (non-posix).
func (f *FlagSet) Int16N(name, shorthand string, value int16, usage string) *int16 {
p := new(int16)
f.Int16VarN(p, name, shorthand, value, usage)
return p
}
// Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 {
p := new(int16)
f.Int16VarP(p, name, shorthand, value, usage)
return p
}
// Int16S is like Int16, but accepts a shorthand letter that can be used after a single dash, alone.
func (f *FlagSet) Int16S(name, shorthand string, value int16, usage string) *int16 {
p := new(int16)
f.Int16VarS(p, name, shorthand, value, usage)
return p
}
// Int16 defines an int16 flag with specified name, default value, and usage string.
// The return value is the address of an int16 variable that stores the value of the flag.
func Int16(name string, value int16, usage string) *int16 {
return CommandLine.Int16(name, value, usage)
}
// Int16N like Int16P, but adds the name as shorthand (non-posix).
func Int16N(name, shorthand string, value int16, usage string) *int16 {
return CommandLine.Int16N(name, shorthand, value, usage)
}
// Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func Int16P(name, shorthand string, value int16, usage string) *int16 {
return CommandLine.Int16P(name, shorthand, value, usage)
}
// Int16S is like Int16, but accepts a shorthand letter that can be used after a single dash, alone.
func Int16S(name, shorthand string, value int16, usage string) *int16 {
return CommandLine.Int16S(name, shorthand, value, usage)
}