10
type uintSliceValue struct {
15
func newUintSliceValue(val []uint, p *[]uint) *uintSliceValue {
16
uisv := new(uintSliceValue)
22
func (s *uintSliceValue) Set(val string) error {
23
ss := strings.Split(val, ",")
24
out := make([]uint, len(ss))
25
for i, d := range ss {
26
u, err := strconv.ParseUint(d, 10, 0)
35
*s.value = append(*s.value, out...)
41
func (s *uintSliceValue) Type() string {
45
func (s *uintSliceValue) String() string {
46
out := make([]string, len(*s.value))
47
for i, d := range *s.value {
48
out[i] = fmt.Sprintf("%d", d)
50
return "[" + strings.Join(out, ",") + "]"
53
func (s *uintSliceValue) fromString(val string) (uint, error) {
54
t, err := strconv.ParseUint(val, 10, 0)
61
func (s *uintSliceValue) toString(val uint) string {
62
return fmt.Sprintf("%d", val)
65
func (s *uintSliceValue) Append(val string) error {
66
i, err := s.fromString(val)
70
*s.value = append(*s.value, i)
74
func (s *uintSliceValue) Replace(val []string) error {
75
out := make([]uint, len(val))
76
for i, d := range val {
78
out[i], err = s.fromString(d)
87
func (s *uintSliceValue) GetSlice() []string {
88
out := make([]string, len(*s.value))
89
for i, d := range *s.value {
90
out[i] = s.toString(d)
95
func uintSliceConv(val string) (interface{}, error) {
96
val = strings.Trim(val, "[]")
97
// Empty string would cause a slice with one (empty) entry
101
ss := strings.Split(val, ",")
102
out := make([]uint, len(ss))
103
for i, d := range ss {
104
u, err := strconv.ParseUint(d, 10, 0)
113
// GetUintSlice returns the []uint value of a flag with the given name.
114
func (f *FlagSet) GetUintSlice(name string) ([]uint, error) {
115
val, err := f.getFlagType(name, "uintSlice", uintSliceConv)
119
return val.([]uint), nil
122
// UintSliceVar defines a uintSlice flag with specified name, default value, and usage string.
123
// The argument p points to a []uint variable in which to store the value of the flag.
124
func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string) {
125
f.VarP(newUintSliceValue(value, p), name, "", usage)
128
// UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
129
func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
130
f.VarP(newUintSliceValue(value, p), name, shorthand, usage)
133
// UintSliceVar defines a uint[] flag with specified name, default value, and usage string.
134
// The argument p points to a uint[] variable in which to store the value of the flag.
135
func UintSliceVar(p *[]uint, name string, value []uint, usage string) {
136
CommandLine.VarP(newUintSliceValue(value, p), name, "", usage)
139
// UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
140
func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
141
CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage)
144
// UintSlice defines a []uint flag with specified name, default value, and usage string.
145
// The return value is the address of a []uint variable that stores the value of the flag.
146
func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint {
148
f.UintSliceVarP(&p, name, "", value, usage)
152
// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
153
func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
155
f.UintSliceVarP(&p, name, shorthand, value, usage)
159
// UintSlice defines a []uint flag with specified name, default value, and usage string.
160
// The return value is the address of a []uint variable that stores the value of the flag.
161
func UintSlice(name string, value []uint, usage string) *[]uint {
162
return CommandLine.UintSliceP(name, "", value, usage)
165
// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
166
func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
167
return CommandLine.UintSliceP(name, shorthand, value, usage)