From 90b831e61ee0ea159e0d00bb0c1ee3cd0c1dcdcd Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 5 Aug 2015 12:46:33 -0400 Subject: String and Int slices called twice should append not overwrite This allows users to do things like ``` cmd --filename=file1 --filename=file2 --filename=file3,file4 ``` And internally we will get ``` []string{"file1", "file2", "file3", "file4"} ``` --- int_slice.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'int_slice.go') diff --git a/int_slice.go b/int_slice.go index fb3e67b..69e7e7c 100644 --- a/int_slice.go +++ b/int_slice.go @@ -25,7 +25,7 @@ func (s *intSliceValue) Set(val string) error { } } - *s = intSliceValue(out) + *s = append(*s, out...) return nil } @@ -38,10 +38,11 @@ func (s *intSliceValue) String() string { for i, d := range *s { out[i] = fmt.Sprintf("%d", d) } - return strings.Join(out, ",") + return "[" + strings.Join(out, ",") + "]" } func intSliceConv(val string) (interface{}, error) { + val = strings.Trim(val, "[]") ss := strings.Split(val, ",") out := make([]int, len(ss)) for i, d := range ss { -- cgit v1.2.3