Skip to content

Commit

Permalink
Move option application earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Jan 22, 2024
1 parent 224c378 commit 894de86
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tm2/pkg/bft/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,24 @@ 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 (
cfg = DefaultConfig()
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
Expand All @@ -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
Expand Down

0 comments on commit 894de86

Please sign in to comment.