Skip to content

Commit

Permalink
Fix deep file parsing not working when flag delimiter is set (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: Emilijus Stankus <e.stankus@nanoavionics.com>
  • Loading branch information
EmilijusS and Emilijus Stankus committed Oct 18, 2021
1 parent 3bc7661 commit e04b381
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions aconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,35 @@ func TestBad(t *testing.T) {
t.Fatalf("want %v, got %v", want, got)
}
}

func TestFileConfigFlagDelim(t *testing.T) {
type TestConfig struct {
Options struct {
Foo float64
Bar float64
}
}
var cfg TestConfig

loader := LoaderFor(&cfg, Config{
SkipDefaults: true,
SkipEnv: true,
SkipFlags: true,
FlagDelimiter: "_",

Files: []string{"testdata/toy.json"},
})

if err := loader.Load(); err != nil {
t.Fatal(err)
}

var want = TestConfig{Options: struct {
Foo float64
Bar float64
}{0.4, 0.25}}

if got := cfg; !reflect.DeepEqual(want, got) {
t.Fatalf("want %v, got %v", want, got)
}
}
5 changes: 4 additions & 1 deletion reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ func (l *Loader) tagsForField(field reflect.StructField) map[string]string {
}

func (l *Loader) fullTag(prefix string, f *fieldData, tag string) string {
sep := l.config.FlagDelimiter
sep := "."
if tag == flagNameTag {
sep = l.config.FlagDelimiter
}
if tag == envNameTag {
sep = l.config.envDelimiter
}
Expand Down

0 comments on commit e04b381

Please sign in to comment.