Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deep file parsing not working when flag delimiter is set #110

Merged
merged 1 commit into from
Oct 18, 2021
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
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