Skip to content

Commit

Permalink
If a valid IP/domain name, use Host title when HostName and `Prox…
Browse files Browse the repository at this point in the history
…yCommand` are not available (Closes #7)
  • Loading branch information
quantumsheep committed Feb 8, 2022
1 parent 5a8e34c commit f882b24
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

valid "github.com/asaskevich/govalidator"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
tb "github.com/nsf/termbox-go"
Expand Down Expand Up @@ -89,25 +90,28 @@ func run(cmd *cobra.Command, args []string) {
}

for _, host := range hosts {
target := host.HostName
if target == "" {
if host.ProxyCommand == "" {
continue
}

if displayFullProxy {
target = host.ProxyCommand
} else {
target = "(Proxy)"
}
}

name := strings.Join(host.Host, " ")

if name[0] == '"' && name[len(name)-1] == '"' {
name = name[1 : len(name)-1]
}

target := host.HostName
if target == "" {
if host.ProxyCommand != "" {
if displayFullProxy {
target = host.ProxyCommand
} else {
target = "(Proxy)"
}
} else if valid.IsIP(name) || valid.IsDNSName(name) {
host.HostName = name
target = name
} else {
continue
}
}

row := []string{name, host.User, target, strconv.Itoa(host.Port)}
table.Rows = append(table.Rows, row)
}
Expand Down

0 comments on commit f882b24

Please sign in to comment.