Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions pkg/context/config/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions pkg/context/config/mock_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"strings"

"github.com/windsorcli/cli/api/v1alpha1"
)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading