Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ func newStringSliceValue(val []string, p *[]string) *stringSliceValue {
return ssv
}

func (s *stringSliceValue) Set(val string) error {
func readAsCSV(val string) ([]string, error) {
if val == "" {
return []string{}, nil
}
stringReader := strings.NewReader(val)
csvReader := csv.NewReader(stringReader)
v, err := csvReader.Read()
return csvReader.Read()
}

func (s *stringSliceValue) Set(val string) error {
v, err := readAsCSV(val)
if err != nil {
return err
}
Expand Down
17 changes: 17 additions & 0 deletions string_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ func TestEmptySS(t *testing.T) {
}
}

func TestEmptySSValue(t *testing.T) {
var ss []string
f := setUpSSFlagSet(&ss)
err := f.Parse([]string{"--ss="})
if err != nil {
t.Fatal("expected no error; got", err)
}

getSS, err := f.GetStringSlice("ss")
if err != nil {
t.Fatal("got an error from GetStringSlice():", err)
}
if len(getSS) != 0 {
t.Fatalf("got ss %v with len=%d but expected length=0", getSS, len(getSS))
}
}

func TestSS(t *testing.T) {
var ss []string
f := setUpSSFlagSet(&ss)
Expand Down