10
type int32SliceValue struct {
15
func newInt32SliceValue(val []int32, p *[]int32) *int32SliceValue {
16
isv := new(int32SliceValue)
22
func (s *int32SliceValue) Set(val string) error {
23
ss := strings.Split(val, ",")
24
out := make([]int32, len(ss))
25
for i, d := range ss {
28
temp64, err = strconv.ParseInt(d, 0, 32)
32
out[i] = int32(temp64)
38
*s.value = append(*s.value, out...)
44
func (s *int32SliceValue) Type() string {
48
func (s *int32SliceValue) String() string {
49
out := make([]string, len(*s.value))
50
for i, d := range *s.value {
51
out[i] = fmt.Sprintf("%d", d)
53
return "[" + strings.Join(out, ",") + "]"
56
func (s *int32SliceValue) fromString(val string) (int32, error) {
57
t64, err := strconv.ParseInt(val, 0, 32)
61
return int32(t64), nil
64
func (s *int32SliceValue) toString(val int32) string {
65
return fmt.Sprintf("%d", val)
68
func (s *int32SliceValue) Append(val string) error {
69
i, err := s.fromString(val)
73
*s.value = append(*s.value, i)
77
func (s *int32SliceValue) Replace(val []string) error {
78
out := make([]int32, len(val))
79
for i, d := range val {
81
out[i], err = s.fromString(d)
90
func (s *int32SliceValue) GetSlice() []string {
91
out := make([]string, len(*s.value))
92
for i, d := range *s.value {
93
out[i] = s.toString(d)
98
func int32SliceConv(val string) (interface{}, error) {
99
val = strings.Trim(val, "[]")
100
// Empty string would cause a slice with one (empty) entry
102
return []int32{}, nil
104
ss := strings.Split(val, ",")
105
out := make([]int32, len(ss))
106
for i, d := range ss {
109
temp64, err = strconv.ParseInt(d, 0, 32)
113
out[i] = int32(temp64)
119
// GetInt32Slice return the []int32 value of a flag with the given name
120
func (f *FlagSet) GetInt32Slice(name string) ([]int32, error) {
121
val, err := f.getFlagType(name, "int32Slice", int32SliceConv)
123
return []int32{}, err
125
return val.([]int32), nil
128
// Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string.
129
// The argument p points to a []int32 variable in which to store the value of the flag.
130
func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string) {
131
f.VarP(newInt32SliceValue(value, p), name, "", usage)
134
// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
135
func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) {
136
f.VarP(newInt32SliceValue(value, p), name, shorthand, usage)
139
// Int32SliceVar defines a int32[] flag with specified name, default value, and usage string.
140
// The argument p points to a int32[] variable in which to store the value of the flag.
141
func Int32SliceVar(p *[]int32, name string, value []int32, usage string) {
142
CommandLine.VarP(newInt32SliceValue(value, p), name, "", usage)
145
// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
146
func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) {
147
CommandLine.VarP(newInt32SliceValue(value, p), name, shorthand, usage)
150
// Int32Slice defines a []int32 flag with specified name, default value, and usage string.
151
// The return value is the address of a []int32 variable that stores the value of the flag.
152
func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32 {
154
f.Int32SliceVarP(&p, name, "", value, usage)
158
// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
159
func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 {
161
f.Int32SliceVarP(&p, name, shorthand, value, usage)
165
// Int32Slice defines a []int32 flag with specified name, default value, and usage string.
166
// The return value is the address of a []int32 variable that stores the value of the flag.
167
func Int32Slice(name string, value []int32, usage string) *[]int32 {
168
return CommandLine.Int32SliceP(name, "", value, usage)
171
// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
172
func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 {
173
return CommandLine.Int32SliceP(name, shorthand, value, usage)