Skip to content

Commit

Permalink
Rename YAMLFlag to ConfigFileLoader
Browse files Browse the repository at this point in the history
The `YAMLFlag` function is solely used for loading config files.

Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed May 13, 2022
1 parent e461ea4 commit e627945
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/util/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Unmarshal(dst Cloneable, sources ...Source) error {
func DefaultUnmarshal(dst Cloneable, args []string, fs *flag.FlagSet) error {
return Unmarshal(dst,
Defaults(fs),
YAMLFlag(args, "config.file"),
ConfigFileLoader(args, "config.file"),
Flags(args, fs),
)
}
6 changes: 3 additions & 3 deletions pkg/util/cfg/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ func DynamicUnmarshal(dst DynamicCloneable, args []string, fs *flag.FlagSet) err
// First populate the config with defaults including flags from the command line
Defaults(fs),
// Next populate the config from the config file, we do this to populate the `common`
// section of the config file by taking advantage of the code in YAMLFlag which will load
// section of the config file by taking advantage of the code in ConfigFileLoader which will load
// and process the config file.
YAMLFlag(args, "config.file"),
ConfigFileLoader(args, "config.file"),
// Apply any dynamic logic to set other defaults in the config. This function is called after parsing the
// config files so that values from a common, or shared, section can be used in
// the dynamic evaluation
dst.ApplyDynamicConfig(),
// Load configs from the config file a second time, this will supersede anything set by the common
// config with values specified in the config file.
YAMLFlag(args, "config.file"),
ConfigFileLoader(args, "config.file"),
// Load the flags again, this will supersede anything set from config file with flags from the command line.
Flags(args, fs),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/cfg/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func dYAML(y []byte) Source {
}
}

func YAMLFlag(args []string, name string) Source {
func ConfigFileLoader(args []string, name string) Source {

return func(dst Cloneable) error {
freshFlags := flag.NewFlagSet("config-file-loader", flag.ContinueOnError)
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/cfg/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func (cfg *testCfg) Clone() flagext.Registerer {
}(*cfg)
}

func TestYAMLFlagDoesNotMutate(t *testing.T) {
func TestConfigFileLoaderDoesNotMutate(t *testing.T) {
cfg := &testCfg{}
err := YAMLFlag(nil, "something")(cfg)
err := ConfigFileLoader(nil, "something")(cfg)
require.Nil(t, err)
require.Equal(t, 0, cfg.v)

Expand Down

0 comments on commit e627945

Please sign in to comment.