Skip to content

Commit

Permalink
Merge 0a5ba61 into 42cdcf5
Browse files Browse the repository at this point in the history
  • Loading branch information
smoliji committed Jun 5, 2020
2 parents 42cdcf5 + 0a5ba61 commit d1eae54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
6 changes: 4 additions & 2 deletions internal/kubectl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func PodsList(namespace string) []*Pod {
portsStr := strings.Split(tokens[2], ",")
ports := make([]int, 0, len(portsStr))
for _, portStr := range portsStr {
port, _ := strconv.Atoi(portStr)
ports = append(ports, port)
port, err := strconv.Atoi(portStr)
if (err == nil) {
ports = append(ports, port)
}
}
pods = append(pods, &Pod{Name: tokens[0], Containers: containers, ContainerPorts: ports, AppLabel: tokens[3]})
}
Expand Down
3 changes: 1 addition & 2 deletions internal/kubectl/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func TestPodsList(t *testing.T) {
expectedItems := []*Pod{
{
Name: "acme-rockets-v0.3.0-74bf544f8b-lzc5b",
// TODO Is it OK to have [0] for <none>? Because it does that now.
ContainerPorts: []int{0},
ContainerPorts: []int{},
Containers: []string{
"event-exporter",
"prometheus-to-sd-exporter",
Expand Down
42 changes: 30 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,36 @@ func readLocalPort(defaultPort int) int {
}

func readRemotePort(containerPorts []int) (port int) {
port, _ = promptSelection(selectField{
titleLoading: "Remote ports",
titleChoose: "Remote port",
getOptions: func() (options []selectFieldOption) {
for _, port := range containerPorts {
options = append(options, selectFieldOption{title: strconv.Itoa(port), value: port})
}
return
},
valueTitle: *flags.remotePort,
}).(int)
return
if (len(containerPorts) > 0) {
port, _ = promptSelection(selectField{
titleLoading: "Remote ports",
titleChoose: "Remote port",
getOptions: func() (options []selectFieldOption) {
for _, port := range containerPorts {
options = append(options, selectFieldOption{title: strconv.Itoa(port), value: port})
}
return
},
valueTitle: *flags.remotePort,
}).(int)
return
}
pickedPort := "3000"
if *flags.remotePort != "" {
pickedPort = *flags.remotePort
fmt.Printf("Choose remote port: %v\n", pickedPort)
} else {
prompt := &survey.Input{
Message: "Choose remote port:",
Default: pickedPort,
}
survey.AskOne(prompt, &pickedPort)
}
n, err := strconv.Atoi(pickedPort)
if err != nil {
log.Fatal(err)
}
return n
}

func readArguments() {
Expand Down

0 comments on commit d1eae54

Please sign in to comment.