@@ -41,6 +41,18 @@ func sshCode(host, dir string, o options) error {
4141 o .sshFlags = strings .Join ([]string {extraSSHFlags , o .sshFlags }, " " )
4242 }
4343
44+ o .bindAddr , err = parseBindAddr (o .bindAddr )
45+ if err != nil {
46+ return xerrors .Errorf ("failed to parse bind address: %w" , err )
47+ }
48+
49+ if o .remotePort == "" {
50+ o .remotePort , err = randomPort ()
51+ }
52+ if err != nil {
53+ return xerrors .Errorf ("failed to find available remote port: %w" , err )
54+ }
55+
4456 dlScript := downloadScript (codeServerPath )
4557
4658 // Downloads the latest code-server and allows it to be executed.
@@ -79,18 +91,6 @@ func sshCode(host, dir string, o options) error {
7991
8092 flog .Info ("starting code-server..." )
8193
82- o .bindAddr , err = parseBindAddr (o .bindAddr )
83- if err != nil {
84- return xerrors .Errorf ("failed to parse bind address: %w" , err )
85- }
86-
87- if o .remotePort == "" {
88- o .remotePort , err = randomPort ()
89- }
90- if err != nil {
91- return xerrors .Errorf ("failed to find available remote port: %w" , err )
92- }
93-
9494 flog .Info ("Tunneling remote port %v to %v" , o .remotePort , o .bindAddr )
9595
9696 sshCmdStr =
@@ -168,19 +168,26 @@ func sshCode(host, dir string, o options) error {
168168}
169169
170170func parseBindAddr (bindAddr string ) (string , error ) {
171+ if bindAddr == "" {
172+ bindAddr = ":"
173+ }
174+
171175 host , port , err := net .SplitHostPort (bindAddr )
172176 if err != nil {
173177 return "" , err
174178 }
179+
175180 if host == "" {
176181 host = "127.0.0.1"
177182 }
183+
178184 if port == "" {
179185 port , err = randomPort ()
180186 }
181187 if err != nil {
182188 return "" , err
183189 }
190+
184191 return net .JoinHostPort (host , port ), nil
185192}
186193
0 commit comments