aboutsummaryrefslogtreecommitdiff
path: root/string_slice.go
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-10-13 14:47:57 -0400
committerEric Paris <[email protected]>2015-10-13 14:47:57 -0400
commit9c1e8f8537a437da36d3a2c8402eb68a44f6dc21 (patch)
tree3f8e79ef36d188da66ef387c4b53cc92540f9b30 /string_slice.go
parentb084184666e02084b8ccb9b704bf0d79c466eb1d (diff)
Use encoding/csv to parse string slices
There was no way to escape or use a , in a string slice so use the encoding/csv library, rather than string.split() and let golang take care of the encoding issues.
Diffstat (limited to 'string_slice.go')
-rw-r--r--string_slice.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/string_slice.go b/string_slice.go
index 0b7ddfe..b53648b 100644
--- a/string_slice.go
+++ b/string_slice.go
@@ -1,6 +1,7 @@
package pflag
import (
+ "encoding/csv"
"fmt"
"strings"
)
@@ -21,7 +22,12 @@ func newStringSliceValue(val []string, p *[]string) *stringSliceValue {
}
func (s *stringSliceValue) Set(val string) error {
- v := strings.Split(val, ",")
+ stringReader := strings.NewReader(val)
+ csvReader := csv.NewReader(stringReader)
+ v, err := csvReader.Read()
+ if err != nil {
+ return err
+ }
if !s.changed {
*s.value = v
} else {