-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint16.go
47 lines (37 loc) · 1.14 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
package clipper
import (
"strconv"
)
type int16Value int16
func newint16Value(val int16, p *int16) *int16Value {
*p = val
return (*int16Value)(p)
}
func (i *int16Value) Set(s string, _ bool) error {
v, err := strconv.ParseInt(s, 0, 16)
if err == nil {
*i = int16Value(v)
}
return err
}
func (iv *int16Value) Reset(i interface{}) {
v := i.(int16)
*iv = int16Value(v)
}
func (i *int16Value) Type() string {
return "int16"
}
func (i *int16Value) Get() interface{} {
return i.GetInt16()
}
func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) }
func (i *int16Value) GetInt16() int16 { return int16(*i) }
// AddInt16 registers an int argument configuration with the command.
// The `name` argument represents the name of the argument.
// The `shortName` argument represents the short alias of the argument.
// If an argument with given `name` is already registered, then panic
// registered `*Opt` object returned.
func (commandConfig *CommandConfig) AddInt16(name, shortName string, value int16, p *int16, help string) *Opt {
v := newint16Value(value, p)
return commandConfig.AddValue(name, shortName, v, false, help)
}