1package pflag
2
3import (
4	"fmt"
5	"strconv"
6)
7
8// -- uint16 value
9type uint32Value uint32
10
11func newUint32Value(val uint32, p *uint32) *uint32Value {
12	*p = val
13	return (*uint32Value)(p)
14}
15func (i *uint32Value) String() string { return fmt.Sprintf("%d", *i) }
16func (i *uint32Value) Set(s string) error {
17	v, err := strconv.ParseUint(s, 0, 32)
18	*i = uint32Value(v)
19	return err
20}
21
22func (i *uint32Value) Type() string {
23	return "uint32"
24}
25
26func uint32Conv(sval string) (interface{}, error) {
27	v, err := strconv.ParseUint(sval, 0, 32)
28	if err != nil {
29		return 0, err
30	}
31	return uint32(v), nil
32}
33
34// GetUint32 return the uint32 value of a flag with the given name
35func (f *FlagSet) GetUint32(name string) (uint32, error) {
36	val, err := f.getFlagType(name, "uint32", uint32Conv)
37	if err != nil {
38		return 0, err
39	}
40	return val.(uint32), nil
41}
42
43// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
44// The argument p points to a uint32 variable in which to store the value of the flag.
45func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) {
46	f.VarP(newUint32Value(value, p), name, "", usage)
47}
48
49// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
50func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
51	f.VarP(newUint32Value(value, p), name, shorthand, usage)
52}
53
54// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
55// The argument p points to a uint32  variable in which to store the value of the flag.
56func Uint32Var(p *uint32, name string, value uint32, usage string) {
57	CommandLine.VarP(newUint32Value(value, p), name, "", usage)
58}
59
60// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
61func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
62	CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
63}
64
65// Uint32 defines a uint32 flag with specified name, default value, and usage string.
66// The return value is the address of a uint32  variable that stores the value of the flag.
67func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
68	p := new(uint32)
69	f.Uint32VarP(p, name, "", value, usage)
70	return p
71}
72
73// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
74func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
75	p := new(uint32)
76	f.Uint32VarP(p, name, shorthand, value, usage)
77	return p
78}
79
80// Uint32 defines a uint32 flag with specified name, default value, and usage string.
81// The return value is the address of a uint32  variable that stores the value of the flag.
82func Uint32(name string, value uint32, usage string) *uint32 {
83	return CommandLine.Uint32P(name, "", value, usage)
84}
85
86// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
87func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
88	return CommandLine.Uint32P(name, shorthand, value, usage)
89}
90