Skip to content

Commit

Permalink
ez: hook up FlattenAnonymousFields for yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinkel committed Mar 20, 2024
1 parent dee6853 commit 3065737
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ez/ez.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3065737

Please sign in to comment.