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