-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint32.go
47 lines (37 loc) · 1.14 KB
/
int32.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 int32Value int32
func newint32Value(val int32, p *int32) *int32Value {
*p = val
return (*int32Value)(p)
}
func (i *int32Value) Set(s string, _ bool) error {
v, err := strconv.ParseInt(s, 0, 32)
if err == nil {
*i = int32Value(v)
}
return err
}
func (iv *int32Value) Reset(i interface{}) {
v := i.(int32)
*iv = int32Value(v)
}
func (i *int32Value) Type() string {
return "int32"
}
func (i *int32Value) Get() interface{} {
return i.GetInt32()
}
func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) }
func (i *int32Value) GetInt32() int32 { return int32(*i) }
// AddInt32 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) AddInt32(name, shortName string, value int32, p *int32, help string) *Opt {
v := newint32Value(value, p)
return commandConfig.AddValue(name, shortName, v, false, help)
}