Merge pull request #1178 from alexcb/master
bugfix: don't overwrite existing stringslice refence
This commit is contained in:
commit
f53989457f
@ -124,7 +124,9 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
|
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
|
||||||
f.Value = &StringSlice{}
|
if f.Value == nil {
|
||||||
|
f.Value = &StringSlice{}
|
||||||
|
}
|
||||||
destination := f.Value
|
destination := f.Value
|
||||||
if f.Destination != nil {
|
if f.Destination != nil {
|
||||||
destination = f.Destination
|
destination = f.Destination
|
||||||
|
14
flag_test.go
14
flag_test.go
@ -386,6 +386,20 @@ func TestStringSliceFlagApply_SetsAllNames(t *testing.T) {
|
|||||||
expect(t, err, nil)
|
expect(t, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStringSliceFlagApply_UsesEnvValues(t *testing.T) {
|
||||||
|
defer resetEnv(os.Environ())
|
||||||
|
os.Clearenv()
|
||||||
|
_ = os.Setenv("MY_GOAT", "vincent van goat,scape goat")
|
||||||
|
var val StringSlice
|
||||||
|
fl := StringSliceFlag{Name: "goat", EnvVars: []string{"MY_GOAT"}, Value: &val}
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
_ = fl.Apply(set)
|
||||||
|
|
||||||
|
err := set.Parse(nil)
|
||||||
|
expect(t, err, nil)
|
||||||
|
expect(t, val.Value(), NewStringSlice("vincent van goat", "scape goat").Value())
|
||||||
|
}
|
||||||
|
|
||||||
func TestStringSliceFlagApply_DefaultValueWithDestination(t *testing.T) {
|
func TestStringSliceFlagApply_DefaultValueWithDestination(t *testing.T) {
|
||||||
defValue := []string{"UA", "US"}
|
defValue := []string{"UA", "US"}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user