mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #102623 from vazmin/bug-cli-string-slice-flag
fix bug where string slice flag is not assigned
This commit is contained in:
commit
a6ef76157b
@ -18,6 +18,7 @@ package flag
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
goflag "flag"
|
goflag "flag"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -45,9 +46,11 @@ func (s *StringSlice) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StringSlice) Set(val string) error {
|
func (s *StringSlice) Set(val string) error {
|
||||||
if s.value == nil || !s.changed {
|
if s.value == nil {
|
||||||
v := make([]string, 0)
|
return fmt.Errorf("no target (nil pointer to []string)")
|
||||||
s.value = &v
|
}
|
||||||
|
if !s.changed {
|
||||||
|
*s.value = make([]string, 0)
|
||||||
}
|
}
|
||||||
*s.value = append(*s.value, val)
|
*s.value = append(*s.value, val)
|
||||||
s.changed = true
|
s.changed = true
|
||||||
|
@ -83,8 +83,8 @@ func TestStringSlice(t *testing.T) {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
t.Errorf("%d: expected nil error, got %v", i, err)
|
t.Errorf("%d: expected nil error, got %v", i, err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(*v.value, test.expected) {
|
if !reflect.DeepEqual(s, test.expected) {
|
||||||
t.Errorf("%d: expected %+v, got %+v", i, test.expected, *v.value)
|
t.Errorf("%d: expected %+v, got %+v", i, test.expected, s)
|
||||||
}
|
}
|
||||||
if v.changed != test.changed {
|
if v.changed != test.changed {
|
||||||
t.Errorf("%d: expected %t got %t", i, test.changed, v.changed)
|
t.Errorf("%d: expected %t got %t", i, test.changed, v.changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user