-
Notifications
You must be signed in to change notification settings - Fork 0
/
uint.go
73 lines (60 loc) · 2.16 KB
/
uint.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
package getopt
import "fmt"
type uintVal uint
func (i *uintVal) String() string {
return fmt.Sprint(uint(*i))
}
func (i *uintVal) Set(val string) error {
_, err := fmt.Sscanf(val, "%d", i)
return err
}
// UintVar defines a uint flag with specified name, default value, and
// usage string. The argument p points to a uint variable in which to
// store the value of the flag.
func (set *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
*p = value
set.Var((*uintVal)(p), name, usage)
}
// UintVar defines a uint flag with specified name, default value, and
// usage string. The argument p points to a uint variable in which to
// store the value of the flag.
func UintVar(p *uint, name string, value uint, usage string) {
CommandLine.UintVar(p, name, value, usage)
}
// Uint defines a uint flag with specified name, default value, and
// usage string. The return value is the address of a uint variable that
// stores the value of the flag.
func (set *FlagSet) Uint(name string, value uint, usage string) *uint {
var b uint
set.UintVar(&b, name, value, usage)
return &b
}
// Uint defines a uint flag with specified name, default value, and
// usage string. The return value is the address of a uint variable that
// stores the value of the flag.
func Uint(name string, value uint, usage string) *uint {
return CommandLine.Uint(name, value, usage)
}
type uint64Val uint64
func (i *uint64Val) String() string {
return fmt.Sprint(uint64(*i))
}
func (i *uint64Val) Set(val string) error {
_, err := fmt.Sscanf(val, "%d", i)
return err
}
// Uint64Var defines a uint64 flag with specified name, default value,
// and usage string. The argument p points to a uint64 variable in which
// to store the value of the flag.
func (set *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
*p = value
set.Var((*uint64Val)(p), name, usage)
}
// Uint64 defines a uint64 flag with specified name, default value, and
// usage string. The return value is the address of a uint64 variable
// that stores the value of the flag.
func (set *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
var b uint64
set.Uint64Var(&b, name, value, usage)
return &b
}