@@ -41,6 +41,18 @@ func sshCode(host, dir string, o options) error {
41
41
o .sshFlags = strings .Join ([]string {extraSSHFlags , o .sshFlags }, " " )
42
42
}
43
43
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
+
44
56
dlScript := downloadScript (codeServerPath )
45
57
46
58
// Downloads the latest code-server and allows it to be executed.
@@ -79,18 +91,6 @@ func sshCode(host, dir string, o options) error {
79
91
80
92
flog .Info ("starting code-server..." )
81
93
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
-
94
94
flog .Info ("Tunneling remote port %v to %v" , o .remotePort , o .bindAddr )
95
95
96
96
sshCmdStr =
@@ -168,19 +168,26 @@ func sshCode(host, dir string, o options) error {
168
168
}
169
169
170
170
func parseBindAddr (bindAddr string ) (string , error ) {
171
+ if bindAddr == "" {
172
+ bindAddr = ":"
173
+ }
174
+
171
175
host , port , err := net .SplitHostPort (bindAddr )
172
176
if err != nil {
173
177
return "" , err
174
178
}
179
+
175
180
if host == "" {
176
181
host = "127.0.0.1"
177
182
}
183
+
178
184
if port == "" {
179
185
port , err = randomPort ()
180
186
}
181
187
if err != nil {
182
188
return "" , err
183
189
}
190
+
184
191
return net .JoinHostPort (host , port ), nil
185
192
}
186
193
0 commit comments