forked from cornfeedhobo/pflag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuint16.go
82 lines (67 loc) · 2.44 KB
/
uint16.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"
)
// -- uint16 value
type uint16Value uint16
var _ Value = (*uint16Value)(nil)
var _ Getter = (*uint16Value)(nil)
var _ Typed = (*uint16Value)(nil)
func newUint16Value(val uint16, p *uint16) *uint16Value {
*p = val
return (*uint16Value)(p)
}
func (i *uint16Value) Set(val string) error {
val = strings.TrimSpace(val)
v, err := strconv.ParseUint(val, 0, 16)
*i = uint16Value(v)
return err
}
func (i *uint16Value) Get() interface{} {
return uint16(*i)
}
func (i *uint16Value) Type() string {
return "uint16"
}
func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
// GetUint16 return the uint16 value of a flag with the given name
func (fs *FlagSet) GetUint16(name string) (uint16, error) {
val, err := fs.getFlagValue(name, "uint16")
if err != nil {
return 0, err
}
return val.(uint16), nil
}
// MustGetUint16 is like GetUint16, but panics on error.
func (fs *FlagSet) MustGetUint16(name string) uint16 {
val, err := fs.GetUint16(name)
if err != nil {
panic(err)
}
return val
}
// Uint16Var defines an uint16 flag with specified name, default value, and usage string.
// The argument p points to an uint16 variable in which to store the value of the flag.
func (fs *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string, opts ...Opt) {
fs.Var(newUint16Value(value, p), name, usage, opts...)
}
// Uint16Var defines an uint16 flag with specified name, default value, and usage string.
// The argument p points to an uint16 variable in which to store the value of the flag.
func Uint16Var(p *uint16, name string, value uint16, usage string, opts ...Opt) {
CommandLine.Uint16Var(p, name, value, usage, opts...)
}
// Uint16 defines an uint16 flag with specified name, default value, and usage string.
// The return value is the address of an uint16 variable that stores the value of the flag.
func (fs *FlagSet) Uint16(name string, value uint16, usage string, opts ...Opt) *uint16 {
var p uint16
fs.Uint16Var(&p, name, value, usage, opts...)
return &p
}
// Uint16 defines an uint16 flag with specified name, default value, and usage string.
// The return value is the address of an uint16 variable that stores the value of the flag.
func Uint16(name string, value uint16, usage string, opts ...Opt) *uint16 {
return CommandLine.Uint16(name, value, usage, opts...)
}