forked from cornfeedhobo/pflag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uint64.go
82 lines (67 loc) · 2.44 KB
/
uint64.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
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zflag
import (
"strconv"
"strings"
)
// -- uint64 Value
type uint64Value uint64
var _ Value = (*uint64Value)(nil)
var _ Getter = (*uint64Value)(nil)
var _ Typed = (*uint64Value)(nil)
func newUint64Value(val uint64, p *uint64) *uint64Value {
*p = val
return (*uint64Value)(p)
}
func (i *uint64Value) Set(val string) error {
val = strings.TrimSpace(val)
v, err := strconv.ParseUint(val, 0, 64)
*i = uint64Value(v)
return err
}
func (i *uint64Value) Get() interface{} {
return uint64(*i)
}
func (i *uint64Value) Type() string {
return "uint64"
}
func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
// GetUint64 return the uint64 value of a flag with the given name
func (fs *FlagSet) GetUint64(name string) (uint64, error) {
val, err := fs.getFlagValue(name, "uint64")
if err != nil {
return 0, err
}
return val.(uint64), nil
}
// MustGetUint64 is like GetUint64, but panics on error.
func (fs *FlagSet) MustGetUint64(name string) uint64 {
val, err := fs.GetUint64(name)
if err != nil {
panic(err)
}
return val
}
// Uint64Var defines an uint64 flag with specified name, default value, and usage string.
// The argument p points to an uint64 variable in which to store the value of the flag.
func (fs *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string, opts ...Opt) {
fs.Var(newUint64Value(value, p), name, usage, opts...)
}
// Uint64Var defines an uint64 flag with specified name, default value, and usage string.
// The argument p points to an uint64 variable in which to store the value of the flag.
func Uint64Var(p *uint64, name string, value uint64, usage string, opts ...Opt) {
CommandLine.Uint64Var(p, name, value, usage, opts...)
}
// Uint64 defines an uint64 flag with specified name, default value, and usage string.
// The return value is the address of an uint64 variable that stores the value of the flag.
func (fs *FlagSet) Uint64(name string, value uint64, usage string, opts ...Opt) *uint64 {
var p uint64
fs.Uint64Var(&p, name, value, usage, opts...)
return &p
}
// Uint64 defines an uint64 flag with specified name, default value, and usage string.
// The return value is the address of an uint64 variable that stores the value of the flag.
func Uint64(name string, value uint64, usage string, opts ...Opt) *uint64 {
return CommandLine.Uint64(name, value, usage, opts...)
}