Handle Empty Port List in PortForward View

mine
Simon Caron 2020-11-23 23:33:10 -05:00
parent 68981ff500
commit 0c40180a4d
2 changed files with 13 additions and 5 deletions

View File

@ -30,7 +30,12 @@ func ShowPortForwards(v ResourceViewer, path string, ports []string, okFn PortFo
SetFieldBackgroundColor(styles.BgColor.Color())
address := v.App().Config.CurrentCluster().PortForwardAddress
p1, p2 := ports[0], extractPort(ports[0])
p1, p2 := "", ""
if len(ports) != 0 {
p1, p2 = ports[0], extractPort(ports[0])
}
f.AddInputField("Container Port:", p1, 30, nil, func(p string) {
p1 = p
})
@ -80,7 +85,13 @@ func ShowPortForwards(v ResourceViewer, path string, ports []string, okFn PortFo
}
modal := tview.NewModalForm(fmt.Sprintf("<PortForward on %s>", path), f)
modal.SetText("Exposed Ports: " + strings.Join(ports, ","))
if len(ports) != 0 {
modal.SetText("Exposed Ports: " + strings.Join(ports, ","))
} else {
modal.SetText("Exposed Ports: (none)")
}
modal.SetTextColor(styles.FgColor.Color())
modal.SetBackgroundColor(styles.BgColor.Color())
modal.SetDoneFunc(func(_ int, b string) {

View File

@ -143,9 +143,6 @@ func showFwdDialog(v ResourceViewer, path string, cb PortForwardCB) error {
ports = append(ports, client.FQN(co, p.Name)+":"+strconv.Itoa(int(p.ContainerPort)))
}
}
if len(ports) == 0 {
return fmt.Errorf("no tcp ports found on %s", path)
}
ShowPortForwards(v, path, ports, cb)
return nil