Skip to content

Commit

Permalink
fix: try fixing merging but it works this way because we have scripts…
Browse files Browse the repository at this point in the history
… and dot is a delimiter
  • Loading branch information
mrexox committed Nov 4, 2024
1 parent 144e436 commit 6d64df6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Load(fs afero.Fs, repo *git.Repository) (*Config, error) {
return &config, nil
}

func read(fs afero.Fs, path string, name string) (*viper.Viper, error) {
func read(fs afero.Fs, name, path string) (*viper.Viper, error) {
v := newViper(fs, path)
v.SetConfigName(name)

Expand All @@ -106,7 +106,7 @@ func newViper(fs afero.Fs, path string) *viper.Viper {

func readOne(fs afero.Fs, path string, names []string) (*viper.Viper, error) {
for _, name := range names {
v, err := read(fs, path, name)
v, err := read(fs, name, path)
if err != nil {
var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); ok {
Expand Down Expand Up @@ -183,7 +183,7 @@ func mergeRemotes(fs afero.Fs, repo *git.Repository, v *viper.Viper, remotes []*
continue
}

if err = merge("remotes", configPath, v); err != nil {
if err = merge(v, "remotes", configPath); err != nil {
return err
}

Expand Down Expand Up @@ -247,23 +247,24 @@ func extendRecursive(fs afero.Fs, root string, v *viper.Viper, extends []string,
}

// merge merges the configuration using viper builtin MergeInConfig.
func merge(name, path string, v *viper.Viper) error {
func merge(v *viper.Viper, name, path string) error {
v.SetConfigName(name)
v.SetConfigFile(path)
return v.MergeInConfig()
}

func mergeLocal(v *viper.Viper) error {
for _, name := range localConfigNames {
err := merge(name, "", v)
if err == nil {
break
}
if err := merge(v, name, ""); err != nil {
var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); ok {
continue
}

var notFoundErr viper.ConfigFileNotFoundError
if ok := errors.As(err, &notFoundErr); !ok {
return err
}

break
}

return nil
Expand Down

0 comments on commit 6d64df6

Please sign in to comment.