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.6
v2.0.7
2 changes: 2 additions & 0 deletions figs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func With(opts Options) Plant {
problems: make([]error, 0),
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
mu: sync.RWMutex{},
mutationsCh: make(chan Mutation),
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
Expand Down
60 changes: 36 additions & 24 deletions internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ func TestTree_checkAndSetFromEnv(t *testing.T) {
// create a new fig tree
var figs *figTree
figs = &figTree{
harvest: 1,
figs: make(map[string]*figFruit),
tracking: false,
withered: make(map[string]witheredFig),
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
mu: sync.RWMutex{},
mutationsCh: make(chan Mutation, 1),
filterTests: true,
harvest: 1,
figs: make(map[string]*figFruit),
tracking: false,
withered: make(map[string]witheredFig),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
mu: sync.RWMutex{},
mutationsCh: make(chan Mutation, 1),
filterTests: true,
}

// assign an int to k
Expand Down Expand Up @@ -61,6 +63,8 @@ func TestTree_setValue(t *testing.T) {
ConfigFilePath string
figs map[string]*figFruit
withered map[string]witheredFig
sources map[string]SourceConfig
sourceLocker sync.RWMutex
mu sync.RWMutex
tracking bool
mutationsCh chan Mutation
Expand All @@ -79,9 +83,11 @@ func TestTree_setValue(t *testing.T) {
{
name: "Set int value",
fields: fields{
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
},
args: args{
flagVal: new(int),
Expand All @@ -93,9 +99,11 @@ func TestTree_setValue(t *testing.T) {
{
name: "Set string value",
fields: fields{
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
},
args: args{
flagVal: new(string),
Expand All @@ -107,9 +115,11 @@ func TestTree_setValue(t *testing.T) {
{
name: "Invalid type",
fields: fields{
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mutationsCh: make(chan Mutation, 1),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
},
args: args{
flagVal: new(float32), // Unsupported type
Expand Down Expand Up @@ -150,13 +160,15 @@ func TestTree_setValue(t *testing.T) {

func TestTree_setValuesFromMap(t *testing.T) {
tree := &figTree{
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
mu: sync.RWMutex{},
tracking: false,
mutationsCh: make(chan Mutation, 1),
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
filterTests: true,
figs: make(map[string]*figFruit),
withered: make(map[string]witheredFig),
sources: make(map[string]SourceConfig),
sourceLocker: sync.RWMutex{},
mu: sync.RWMutex{},
tracking: false,
mutationsCh: make(chan Mutation, 1),
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
filterTests: true,
}
m := map[string]interface{}{
"name": "yahuah",
Expand Down
7 changes: 6 additions & 1 deletion list_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ func (l *ListFlag) String() string {
return strings.Join(*l.values, ",")
}

// PolicyListAppend will apply ListFlag.Set to the list of values and not append to any existing values in the ListFlag
var PolicyListAppend bool = false

// Set unpacks a comma separated value argument and appends items to the list of []string
func (l *ListFlag) Set(value string) error {
if l.values == nil {
l.values = &[]string{}
}
items := strings.Split(value, ",")
*l.values = append(*l.values, items...)
if PolicyListAppend {
*l.values = append(*l.values, items...)
}
return nil
}
42 changes: 42 additions & 0 deletions source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package figtree

type SourceKind int

const (
SourceKindUnknown SourceKind = iota
SourceKindEnv
SourceKindFile
SourceKindFlag
SourceKindFlagEnv
)

type SourceConfig interface {
Fetch() (string, error)
Kind() SourceKind
}

func (tree *figTree) WithSource(source SourceConfig) error {
return nil
}

func (tree *figTree) Source(name string) error {
tree.mu.RLock()
source, exists := tree.sources[name]
tree.mu.RUnlock()
if !exists {
return ErrSourceNotFound{}
}
result, err := source.Fetch()
if err != nil {
return err
}
tree.StoreString(name, result)

return nil
}

type ErrSourceNotFound struct{}

func (e ErrSourceNotFound) Error() string {
return "source not found"
}
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Plant interface {
// Fig returns a figFruit from the figTree by its name
Fig(name string) Flesh

// Source runs the attached WithSource against the SourceConfig
Source(name string) error

// WithValidator binds a figValidatorFunc to a figFruit that returns Plant
WithValidator(name string, validator func(interface{}) error) Plant

Expand Down Expand Up @@ -142,6 +145,8 @@ type figTree struct {
pollinate bool
figs map[string]*figFruit
withered map[string]witheredFig
sources map[string]SourceConfig
sourceLocker sync.RWMutex
mu sync.RWMutex
tracking bool
problems []error
Expand Down
Loading