Skip to content

Commit

Permalink
Fix packages flag
Browse files Browse the repository at this point in the history
It should split on any whitespace
  • Loading branch information
dnephin committed Jun 11, 2020
1 parent dcc31b5 commit 3381e15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ func (c *commandValue) Value() []string {
var _ pflag.Value = (*stringSlice)(nil)

// stringSlice is a flag.Value which populates the string slice by splitting
// the raw flag value on spaces.
// the raw flag value on whitespace.
type stringSlice []string

func (s *stringSlice) String() string {
return strings.Join(*s, " ")
}

func (s *stringSlice) Set(raw string) error {
*s = append(*s, strings.Split(raw, " ")...)
*s = append(*s, strings.Fields(raw)...)
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ func TestNoSummaryValue_SetAndString(t *testing.T) {
assert.ErrorContains(t, value.Set("bogus"), "must be one or more of")
})
}

func TestStringSlice(t *testing.T) {
value := "one \ntwo three\n\tfour\t five \n"
var v []string
ss := (*stringSlice)(&v)
assert.NilError(t, ss.Set(value))
assert.DeepEqual(t, v, []string{"one", "two", "three", "four", "five"})
}

0 comments on commit 3381e15

Please sign in to comment.