mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-26 19:08:25 +00:00
Add a message for empty contexts
This commit is contained in:
parent
51c61b862d
commit
f95e54131e
@ -23,6 +23,7 @@ type InteractiveSwitchOp struct {
|
||||
func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
// parse kubeconfig just to see if it can be loaded
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
defer kc.Close()
|
||||
if err := kc.Parse(); err != nil {
|
||||
if cmdutil.IsNotFoundErr(err) {
|
||||
printer.Warning(stderr, "kubeconfig file not found")
|
||||
@ -30,7 +31,12 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
}
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
kc.Close()
|
||||
|
||||
ctxs := kc.ContextNames()
|
||||
if ctxs == nil {
|
||||
err := printer.Warning(stderr, "No kubectl context found")
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
|
||||
cmd := exec.Command("fzf", "--ansi", "--no-preview")
|
||||
var out bytes.Buffer
|
||||
|
Loading…
Reference in New Issue
Block a user