diff --git a/pkg/api/kubeconfig.go b/pkg/api/kubeconfig.go index 168d197..04b4ffb 100644 --- a/pkg/api/kubeconfig.go +++ b/pkg/api/kubeconfig.go @@ -6,7 +6,6 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd/api" - "log" "slices" ) @@ -55,7 +54,6 @@ func (r *KubeConfig) GetCurrentNamespace() string { } func (r *KubeConfig) GetNamespacesInContext(context string) ([]string, error) { - log.Printf("Getting namespaces in context %s", context) var namespaces []string oldContext := r.config.CurrentContext @@ -75,10 +73,7 @@ func (r *KubeConfig) GetNamespacesInContext(context string) ([]string, error) { namespaces = ns } - log.Printf("Found %d namespaces", len(namespaces)) - if oldContext != context { - log.Printf("Switching back to old context") if err := r.SwitchContext(context); err != nil { return namespaces, err } @@ -88,7 +83,6 @@ func (r *KubeConfig) GetNamespacesInContext(context string) ([]string, error) { } func (r *KubeConfig) SwitchContext(context string) error { - log.Printf("Switching to context %s", context) r.config.CurrentContext = context return r.updateConfig(r.config) } diff --git a/pkg/cmd/cs.go b/pkg/cmd/cs.go index e76e371..b4e10de 100644 --- a/pkg/cmd/cs.go +++ b/pkg/cmd/cs.go @@ -114,6 +114,9 @@ func (o *ContextSwitcherOptions) Complete(args []string) error { func (o *ContextSwitcherOptions) interpretTask(value string) { components := strings.Split(value, ":") + if len(components) != 2 { + return + } if components[0] != "" { o.context = components[0] o.task = TaskSwitchContext @@ -132,7 +135,7 @@ func (o *ContextSwitcherOptions) Validate() error { return fmt.Errorf("wrong argument specified") } - if o.task == TaskSwitchBoth || o.task == TaskSwitchContext && + if (o.task == TaskSwitchBoth || o.task == TaskSwitchContext) && !funk.ContainsString(funk.Keys(o.rawConfig.Contexts).([]string), o.context) { return fmt.Errorf("selected context does not exist") } diff --git a/pkg/ui/selection_list.go b/pkg/ui/selection_list.go index 51f45b9..799d6bc 100644 --- a/pkg/ui/selection_list.go +++ b/pkg/ui/selection_list.go @@ -25,7 +25,6 @@ type SelectionList struct { var _ tea.Model = SelectionList{} func NewSelectionList(title string, kubeConfigAPI api.KubeConfig, onlyCurrentContext bool) SelectionList { - _, _ = tea.LogToFile("/tmp/cslog", "debug") d := list.NewDefaultDelegate() d.SetSpacing(0) d.ShowDescription = false