From d17603b1212f1fc0cd603c31a6c19f8d297e8d57 Mon Sep 17 00:00:00 2001 From: David Finkel Date: Wed, 20 Mar 2024 10:08:17 -0400 Subject: [PATCH] ez: hook up FlattenAnonymousFields for yaml --- ez/ez.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ez/ez.go b/ez/ez.go index 6bea267..5ec1aba 100644 --- a/ez/ez.go +++ b/ez/ez.go @@ -82,6 +82,12 @@ type Params[T any] struct { // Note that this does not affect the flags or environment variable // naming. To manipulate flag naming, see [Params.FlagConfig]. FileFieldNameEncoder caseconversion.EncodeCasingFunc + + // FlattenAnonymousFields inserts the AnonymousFlattenMangler into the + // chain so decoders that do not handle anonymous fields never see such + // things. + // (Currently only affects the yaml decoder) + FlattenAnonymousFields bool } // DecoderFactory should return the appropriate decoder based on the config file @@ -243,7 +249,7 @@ func ConfigFileEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, c // YAMLConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly // wraping ConfigFileEnvFlag with the decoder statically set to YAML. func YAMLConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error) { - return ConfigFileEnvFlag(ctx, cfg, func(string) dials.Decoder { return &yaml.Decoder{} }, params) + return ConfigFileEnvFlag(ctx, cfg, func(string) dials.Decoder { return &yaml.Decoder{FlattenAnonymous: params.FlattenAnonymousFields} }, params) } // JSONConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly