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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.7
v2.0.8
3 changes: 2 additions & 1 deletion assure_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package figtree

import (
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestSomeAssurances(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion callback_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions list_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
29 changes: 28 additions & 1 deletion list_flag_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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]}
})
}
5 changes: 5 additions & 0 deletions map_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 29 additions & 1 deletion map_flag_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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]}
})

}
3 changes: 2 additions & 1 deletion parsing_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion rules_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions savior.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion savior_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Loading