diff options
| author | wu8685 <[email protected]> | 2016-08-19 10:41:12 +0800 |
|---|---|---|
| committer | wu8685 <[email protected]> | 2016-08-19 10:41:12 +0800 |
| commit | d68ef7c38c75152f9dac79bc635bd070b70d0913 (patch) | |
| tree | c65cf07d70dfbd07a44366523d988cd567e2659f /string_slice.go | |
| parent | 4f9190456aed1c2113ca51ea9b89219747458dc1 (diff) | |
Fix bug in FlagSet.GetStringSlice when a comma in a string slice value
Diffstat (limited to 'string_slice.go')
| -rw-r--r-- | string_slice.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/string_slice.go b/string_slice.go index f2a49d9..927a440 100644 --- a/string_slice.go +++ b/string_slice.go @@ -1,6 +1,7 @@ package pflag import ( + "bytes" "encoding/csv" "fmt" "strings" @@ -48,7 +49,13 @@ func (s *stringSliceValue) Type() string { return "stringSlice" } -func (s *stringSliceValue) String() string { return "[" + strings.Join(*s.value, ",") + "]" } +func (s *stringSliceValue) String() string { + b := &bytes.Buffer{} + w := csv.NewWriter(b) + w.Write(*s.value) + w.Flush() + return "[" + strings.TrimSuffix(b.String(), fmt.Sprintln()) + "]" +} func stringSliceConv(sval string) (interface{}, error) { sval = strings.Trim(sval, "[]") @@ -56,8 +63,7 @@ func stringSliceConv(sval string) (interface{}, error) { if len(sval) == 0 { return []string{}, nil } - v := strings.Split(sval, ",") - return v, nil + return readAsCSV(sval) } // GetStringSlice return the []string value of a flag with the given name |
