Skip to content

Commit

Permalink
Merge pull request #16 from hazelops/TOOLS-71-tunnel-ports
Browse files Browse the repository at this point in the history
TOOLS-71 add print ssh tunnel ports
  • Loading branch information
psihachina authored Oct 28, 2021
2 parents ca80f26 + 6897f6f commit 776437c
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 776437c

Please sign in to comment.