diff --git a/VERSION b/VERSION index d8ba80f..923fd4d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.7 +v2.0.8 diff --git a/assure_test.go b/assure_test.go index 1936bbd..89e2ed0 100644 --- a/assure_test.go +++ b/assure_test.go @@ -1,9 +1,10 @@ package figtree import ( - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestSomeAssurances(t *testing.T) { diff --git a/callback_test.go b/callback_test.go index 574262c..d25c03c 100644 --- a/callback_test.go +++ b/callback_test.go @@ -1,9 +1,10 @@ package figtree import ( - "github.com/stretchr/testify/assert" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestTree_WithCallback(t *testing.T) { diff --git a/list_flag.go b/list_flag.go index c56344a..93c670d 100644 --- a/list_flag.go +++ b/list_flag.go @@ -45,6 +45,8 @@ func (l *ListFlag) Set(value string) error { items := strings.Split(value, ",") if PolicyListAppend { *l.values = append(*l.values, items...) + } else { + *l.values = items } return nil } diff --git a/list_flag_test.go b/list_flag_test.go index a86360b..f6d3fa1 100644 --- a/list_flag_test.go +++ b/list_flag_test.go @@ -1,8 +1,10 @@ package figtree import ( - "github.com/stretchr/testify/assert" + "os" "testing" + + "github.com/stretchr/testify/assert" ) func TestTree_ListValues(t *testing.T) { @@ -11,3 +13,28 @@ func TestTree_ListValues(t *testing.T) { assert.NoError(t, figs.Parse()) assert.Contains(t, *figs.List(t.Name()), "yahuah") } + +func TestListFlag_Set(t *testing.T) { + t.Run("PolicyListAppend_TRUE", func(t *testing.T) { + PolicyListAppend = true + os.Args = []string{os.Args[0], "-x", "yahuah"} + figs := With(Options{Germinate: true}) + figs.NewList("x", []string{"bum"}, "Name List") + assert.NoError(t, figs.Parse()) + assert.Equal(t, "", figs.Fig("x").ToString()) + assert.Contains(t, *figs.List("x"), "yahuah") + assert.Contains(t, *figs.List("x"), "bum") // Contains because of PolicyListAppend + os.Args = []string{os.Args[0]} + }) + t.Run("PolicyListAppend_DEFAULT", func(t *testing.T) { + PolicyListAppend = false + os.Args = []string{os.Args[0], "-x", "yahuah"} + figs := With(Options{Germinate: true}) + figs.NewList("x", []string{"bum"}, "Name List") + assert.NoError(t, figs.Parse()) + assert.Equal(t, "", figs.Fig("x").ToString()) + assert.Contains(t, *figs.List("x"), "yahuah") + assert.NotContains(t, *figs.List("x"), "bum") // NotContains because of PolicyListAppend + os.Args = []string{os.Args[0]} + }) +} diff --git a/map_flag.go b/map_flag.go index 600728f..d53b2e9 100644 --- a/map_flag.go +++ b/map_flag.go @@ -66,11 +66,16 @@ func (m *MapFlag) String() string { return strings.Join(entries, ",") } +var PolicyMapAppend = false + // Set accepts a value like KEY=VALUE,KEY=VALUE,KEY=VALUE to override map values func (m *MapFlag) Set(value string) error { if m.values == nil { m.values = &map[string]string{} } + if !PolicyMapAppend { + m.values = &map[string]string{} + } pairs := strings.Split(value, ",") for _, pair := range pairs { kv := strings.SplitN(pair, "=", 2) diff --git a/map_flag_test.go b/map_flag_test.go index 18b23b5..fc37433 100644 --- a/map_flag_test.go +++ b/map_flag_test.go @@ -1,8 +1,10 @@ package figtree import ( - "github.com/stretchr/testify/assert" + "os" "testing" + + "github.com/stretchr/testify/assert" ) func TestTree_MapKeys(t *testing.T) { @@ -11,3 +13,29 @@ func TestTree_MapKeys(t *testing.T) { assert.NoError(t, figs.Parse()) assert.Contains(t, figs.MapKeys(t.Name()), "name") } + +func TestMapFlag_Set(t *testing.T) { + t.Run("PolicyMapAppend_TRUE", func(t *testing.T) { + PolicyMapAppend = true + os.Args = []string{os.Args[0], "-x", "name=yahuah"} + figs := With(Options{Germinate: true}) + figs.NewMap("x", map[string]string{"job": "bum"}, "Name Map") + assert.NoError(t, figs.Parse()) + assert.Equal(t, "", figs.Fig("x").ToString()) + assert.Contains(t, figs.MapKeys("x"), "name") + assert.Contains(t, figs.MapKeys("x"), "job") // Contains because of PolicyMapAppend + os.Args = []string{os.Args[0]} + }) + t.Run("PolicyMapAppend_DEFAULT", func(t *testing.T) { + PolicyMapAppend = false + os.Args = []string{os.Args[0], "-x", "name=yahuah"} + figs := With(Options{Germinate: true}) + figs.NewMap("x", map[string]string{"job": "bum"}, "Name Map") + assert.NoError(t, figs.Parse()) + assert.Equal(t, "", figs.Fig("x").ToString()) + assert.Contains(t, figs.MapKeys("x"), "name") + assert.NotContains(t, figs.MapKeys("x"), "job") // NotContains because no PolicyMapAppend + os.Args = []string{os.Args[0]} + }) + +} diff --git a/parsing_test.go b/parsing_test.go index e505df3..a1df2f9 100644 --- a/parsing_test.go +++ b/parsing_test.go @@ -1,9 +1,10 @@ package figtree import ( - "github.com/stretchr/testify/assert" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func TestTree_Parse(t *testing.T) { diff --git a/rules_test.go b/rules_test.go index 125bcb2..e833f5b 100644 --- a/rules_test.go +++ b/rules_test.go @@ -1,11 +1,12 @@ package figtree import ( - "github.com/stretchr/testify/assert" "os" "sync" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestRules(t *testing.T) { diff --git a/savior.go b/savior.go index a5f5ddc..9ae3a13 100644 --- a/savior.go +++ b/savior.go @@ -4,10 +4,11 @@ import ( "encoding/json" "errors" "fmt" - "github.com/go-ini/ini" - "gopkg.in/yaml.v3" "os" "path/filepath" + + "github.com/go-ini/ini" + "gopkg.in/yaml.v3" ) func (tree *figTree) ReadFrom(path string) error { diff --git a/savior_test.go b/savior_test.go index 1bfb44d..22f05d8 100644 --- a/savior_test.go +++ b/savior_test.go @@ -1,10 +1,11 @@ package figtree import ( - "github.com/stretchr/testify/assert" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func TestFigTree_ReadFile(t *testing.T) {