From 4a511557d8b400500de945e3ffd624e78cfa11dd Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Tue, 22 Apr 2025 18:12:28 -0400 Subject: [PATCH 1/2] support previous activeprofile key --- internal/profiles/koanf.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/profiles/koanf.go b/internal/profiles/koanf.go index 682c5fd7..aa7c7a89 100644 --- a/internal/profiles/koanf.go +++ b/internal/profiles/koanf.go @@ -69,8 +69,18 @@ func KoanfValueFromOption(opt options.Option, pName string) (value string, ok bo ) // Case 1: Koanf Key is the ActiveProfile Key, get value from main koanf instance - if opt.KoanfKey != "" && opt.KoanfKey == options.RootActiveProfileOption.KoanfKey && mainKoanfInstance != nil { - kValue = mainKoanfInstance.KoanfInstance().Get(opt.KoanfKey) + if opt.KoanfKey != "" && strings.EqualFold(opt.KoanfKey, options.RootActiveProfileOption.KoanfKey) && mainKoanfInstance != nil { + oldActiveProfileKey := mainKoanfInstance.KoanfInstance().Get("activeprofile") + if oldActiveProfileKey != nil { + kStringValue, ok := oldActiveProfileKey.(string) + if ok { + kValue = mainKoanfInstance.KoanfInstance().Get(kStringValue) + } else { + return "", false, fmt.Errorf("error getting koanf string value for key %s: %w", opt.KoanfKey, err) + } + } else { + kValue = mainKoanfInstance.KoanfInstance().Get(opt.KoanfKey) + } } else { // // Case 2: --profile flag has been set, get value from set profile koanf instance // // Case 3: no --profile flag set, get value from active profile koanf instance defined in main koanf instance @@ -126,7 +136,7 @@ func (k KoanfConfig) ProfileNames() (profileNames []string) { mainKoanfKeys := k.KoanfInstance().All() for key := range mainKoanfKeys { // Do not add Active profile koanf key to profileNames - if key == options.RootActiveProfileOption.KoanfKey { + if strings.EqualFold(key, options.RootActiveProfileOption.KoanfKey) { continue } @@ -291,7 +301,7 @@ func (k KoanfConfig) DefaultMissingKoanfKeys() (err error) { } for _, opt := range options.Options() { - if opt.KoanfKey == "" || opt.KoanfKey == options.RootActiveProfileOption.KoanfKey { + if opt.KoanfKey == "" || strings.EqualFold(opt.KoanfKey, options.RootActiveProfileOption.KoanfKey) { continue } From 8b3a990a2e6bf51dbcfda32d41ff66796a158abd Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Tue, 22 Apr 2025 18:44:54 -0400 Subject: [PATCH 2/2] reduce logic checking for existing activeprofile key --- internal/profiles/koanf.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/profiles/koanf.go b/internal/profiles/koanf.go index aa7c7a89..61dbc165 100644 --- a/internal/profiles/koanf.go +++ b/internal/profiles/koanf.go @@ -70,15 +70,8 @@ func KoanfValueFromOption(opt options.Option, pName string) (value string, ok bo // Case 1: Koanf Key is the ActiveProfile Key, get value from main koanf instance if opt.KoanfKey != "" && strings.EqualFold(opt.KoanfKey, options.RootActiveProfileOption.KoanfKey) && mainKoanfInstance != nil { - oldActiveProfileKey := mainKoanfInstance.KoanfInstance().Get("activeprofile") - if oldActiveProfileKey != nil { - kStringValue, ok := oldActiveProfileKey.(string) - if ok { - kValue = mainKoanfInstance.KoanfInstance().Get(kStringValue) - } else { - return "", false, fmt.Errorf("error getting koanf string value for key %s: %w", opt.KoanfKey, err) - } - } else { + kValue = mainKoanfInstance.KoanfInstance().Get("activeprofile") + if kValue == nil { kValue = mainKoanfInstance.KoanfInstance().Get(opt.KoanfKey) } } else {