diff --git a/pkg/context/config/config_handler.go b/pkg/context/config/config_handler.go index 9301e71dd..9e24c1c9c 100644 --- a/pkg/context/config/config_handler.go +++ b/pkg/context/config/config_handler.go @@ -35,6 +35,7 @@ type ConfigHandler interface { SetDefault(context v1alpha1.Context) error GetConfig() *v1alpha1.Context GetContext() string + IsDevMode(contextName string) bool SetContext(context string) error GetConfigRoot() (string, error) Clean() error @@ -679,6 +680,18 @@ func (c *configHandler) GetContext() string { } } +// IsDevMode checks if the given context name represents a dev/local environment. +// It first checks if "dev" is explicitly set in the configuration, which takes precedence. +// If not set, it falls back to checking if the context name equals "local" or starts with "local-". +func (c *configHandler) IsDevMode(contextName string) bool { + if devValue := c.Get("dev"); devValue != nil { + if devBool, ok := devValue.(bool); ok { + return devBool + } + } + return contextName == "local" || strings.HasPrefix(contextName, "local-") +} + // SetContext sets the current context in the file and updates the cache func (c *configHandler) SetContext(context string) error { projectRoot, err := c.shell.GetProjectRoot() diff --git a/pkg/context/config/mock_config_handler.go b/pkg/context/config/mock_config_handler.go index a706a5de0..4d3f92b0b 100644 --- a/pkg/context/config/mock_config_handler.go +++ b/pkg/context/config/mock_config_handler.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "strings" "github.com/windsorcli/cli/api/v1alpha1" ) @@ -23,6 +24,7 @@ type MockConfigHandler struct { SetDefaultFunc func(context v1alpha1.Context) error GetConfigFunc func() *v1alpha1.Context GetContextFunc func() string + IsDevModeFunc func(contextName string) bool SetContextFunc func(context string) error GetConfigRootFunc func() (string, error) CleanFunc func() error @@ -180,6 +182,14 @@ func (m *MockConfigHandler) GetContext() string { return "mock-context" } +// IsDevMode calls the mock IsDevModeFunc if set, otherwise returns default dev mode logic +func (m *MockConfigHandler) IsDevMode(contextName string) bool { + if m.IsDevModeFunc != nil { + return m.IsDevModeFunc(contextName) + } + return contextName == "local" || strings.HasPrefix(contextName, "local-") +} + // SetContext calls the mock SetContextFunc if set, otherwise returns nil func (m *MockConfigHandler) SetContext(context string) error { if m.SetContextFunc != nil {