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 uintSliceConv(val string) (interface{}, error) {
54 val = strings.Trim(val, "[]")
55 // Empty string would cause a slice with one (empty) entry
59 ss := strings.Split(val, ",")
60 out := make([]uint, len(ss))
61 for i, d := range ss {
62 u, err := strconv.ParseUint(d, 10, 0)
71 // GetUintSlice returns the []uint value of a flag with the given name.
72 func (f *FlagSet) GetUintSlice(name string) ([]uint, error) {
73 val, err := f.getFlagType(name, "uintSlice", uintSliceConv)
77 return val.([]uint), nil
80 // UintSliceVar defines a uintSlice flag with specified name, default value, and usage string.
81 // The argument p points to a []uint variable in which to store the value of the flag.
82 func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string) {
83 f.VarP(newUintSliceValue(value, p), name, "", usage)
86 // UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
87 func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
88 f.VarP(newUintSliceValue(value, p), name, shorthand, usage)
91 // UintSliceVar defines a uint[] flag with specified name, default value, and usage string.
92 // The argument p points to a uint[] variable in which to store the value of the flag.
93 func UintSliceVar(p *[]uint, name string, value []uint, usage string) {
94 CommandLine.VarP(newUintSliceValue(value, p), name, "", usage)
97 // UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
98 func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
99 CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage)
102 // UintSlice defines a []uint flag with specified name, default value, and usage string.
103 // The return value is the address of a []uint variable that stores the value of the flag.
104 func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint {
106 f.UintSliceVarP(&p, name, "", value, usage)
110 // UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
111 func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
113 f.UintSliceVarP(&p, name, shorthand, value, usage)
117 // UintSlice defines a []uint flag with specified name, default value, and usage string.
118 // The return value is the address of a []uint variable that stores the value of the flag.
119 func UintSlice(name string, value []uint, usage string) *[]uint {
120 return CommandLine.UintSliceP(name, "", value, usage)
123 // UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
124 func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
125 return CommandLine.UintSliceP(name, shorthand, value, usage)