Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/profiles/koanf.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ func (k KoanfConfig) GetProfileKoanf(pName string) (subKoanf *koanf.Koanf, err e
}

func (k KoanfConfig) WriteFile() (err error) {
// TODO - Remove this for loop prior to v0.7.0 release
for _, profileName := range k.ProfileNames() {
for key, val := range k.KoanfInstance().All() {
if profileName == key || !strings.Contains(key, profileName) {
continue
}
for _, opt := range options.Options() {
fullKoanfKeyValue := fmt.Sprintf("%s.%s", profileName, opt.KoanfKey)
if fullKoanfKeyValue == key {
continue
}
if strings.ToLower(fullKoanfKeyValue) == key {
err = k.KoanfInstance().Set(fullKoanfKeyValue, val)
if err != nil {
return fmt.Errorf("error setting koanf key %s: %w", fullKoanfKeyValue, err)
}
k.KoanfInstance().Delete(key)
}
}
}
}

// TODO - Remove this originalActiveProfileKey logic prior to v0.7.0 release
// Delete the original active profile key if it exists and the new activeProfile exists
originalActiveProfileKey := strings.ToLower(options.RootActiveProfileOption.KoanfKey)
if k.KoanfInstance().Exists(originalActiveProfileKey) && k.KoanfInstance().Exists(options.RootActiveProfileOption.KoanfKey) {
k.KoanfInstance().Delete(strings.ToLower(originalActiveProfileKey))
}

encodedConfig, err := k.KoanfInstance().Marshal(yaml.Parser())
if err != nil {
return fmt.Errorf("error marshalling koanf: %w", err)
Expand Down