fix: skip fzf launch in kubens when no contexts exist in kubeconfig

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ahmet Alp Balkan
2026-03-09 00:28:28 -07:00
parent 039f5ed1ef
commit 711beb5fc5

View File

@@ -46,6 +46,14 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
return fmt.Errorf("kubeconfig error: %w", err)
}
ctxNames, err := kc.ContextNames()
if err != nil {
return fmt.Errorf("failed to get context names: %w", err)
}
if len(ctxNames) == 0 {
return errors.New("no contexts found in the kubeconfig file")
}
cmd := exec.Command("fzf", "--ansi", "--no-preview")
var out bytes.Buffer
cmd.Stdin = os.Stdin