diff --git a/tm2/pkg/bft/config/config.go b/tm2/pkg/bft/config/config.go index c498b0893b7..e5c331b448c 100644 --- a/tm2/pkg/bft/config/config.go +++ b/tm2/pkg/bft/config/config.go @@ -43,8 +43,11 @@ func DefaultConfig() *Config { type Option func(cfg *Config) -// LoadOrMakeConfigWithOptions loads configuration or saves one -// made by modifying the default config with override options +// LoadOrMakeConfigWithOptions loads the configuration located in the given +// root directory, at [defaultConfigFilePath]. +// +// If the config does not exist, it is created, starting from the values in +// `DefaultConfig` and applying the defaults in opts. func LoadOrMakeConfigWithOptions(root string, opts ...Option) (*Config, error) { // Initialize the config as default var ( @@ -52,6 +55,12 @@ func LoadOrMakeConfigWithOptions(root string, opts ...Option) (*Config, error) { configPath = join(root, defaultConfigFilePath) ) + // Config doesn't exist, create it + // from the default one + for _, opt := range opts { + opt(cfg) + } + // Check if the config exists if osm.FileExists(configPath) { // Load the configuration @@ -76,12 +85,6 @@ func LoadOrMakeConfigWithOptions(root string, opts ...Option) (*Config, error) { return loadedCfg, nil } - // Config doesn't exist, create it - // from the default one - for _, opt := range opts { - opt(cfg) - } - cfg.SetRootDir(root) // Make sure the directories are initialized