Skip to content

Commit

Permalink
TOOLS-71 add print ssh tunnel ports
Browse files Browse the repository at this point in the history
  • Loading branch information
psihachina committed Oct 28, 2021
1 parent ca80f26 commit 6897f6f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/commands/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"os/exec"
"regexp"
"strings"
"syscall"

Expand Down Expand Up @@ -265,6 +266,11 @@ func (c *tunnelCmd) SSHTunnelConfigCreate() error {
return err
}

re, err := regexp.Compile(`LocalForward\s(?P<localPort>\d+)\s(?P<remoteHost>.+):(?P<remotePort>\d+)`)
if err != nil {
return err
}

var config string

defer f.Close()
Expand All @@ -279,7 +285,15 @@ func (c *tunnelCmd) SSHTunnelConfigCreate() error {

pterm.Success.Printfln("Writing SSH Tunnel config to file")

pterm.Info.Print(config)
res := re.FindAllStringSubmatch(config, -1)

ports := "SSH Tunnel Available:\n"

for _, v := range res {
ports += fmt.Sprintf("%s:%s => localhost:%s\n", v[2], v[3], v[1])
}

pterm.Info.Print(ports)

return nil
}
Expand Down

0 comments on commit 6897f6f

Please sign in to comment.