@@ -53,7 +53,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
53
53
waitEnum string
54
54
noWait bool
55
55
logDirPath string
56
- remoteForward string
56
+ remoteForwards [] string
57
57
disableAutostart bool
58
58
)
59
59
client := new (codersdk.Client )
@@ -135,13 +135,15 @@ func (r *RootCmd) ssh() *clibase.Cmd {
135
135
stack := newCloserStack (ctx , logger )
136
136
defer stack .close (nil )
137
137
138
- if remoteForward != "" {
139
- isValid := validateRemoteForward (remoteForward )
140
- if ! isValid {
141
- return xerrors .Errorf (`invalid format of remote-forward, expected: remote_port:local_address:local_port` )
142
- }
143
- if isValid && stdio {
144
- return xerrors .Errorf (`remote-forward can't be enabled in the stdio mode` )
138
+ if len (remoteForwards ) > 0 {
139
+ for _ , remoteForward := range remoteForwards {
140
+ isValid := validateRemoteForward (remoteForward )
141
+ if ! isValid {
142
+ return xerrors .Errorf (`invalid format of remote-forward, expected: remote_port:local_address:local_port` )
143
+ }
144
+ if isValid && stdio {
145
+ return xerrors .Errorf (`remote-forward can't be enabled in the stdio mode` )
146
+ }
145
147
}
146
148
}
147
149
@@ -311,18 +313,20 @@ func (r *RootCmd) ssh() *clibase.Cmd {
311
313
}
312
314
}
313
315
314
- if remoteForward != "" {
315
- localAddr , remoteAddr , err := parseRemoteForward (remoteForward )
316
- if err != nil {
317
- return err
318
- }
316
+ if len (remoteForwards ) > 0 {
317
+ for _ , remoteForward := range remoteForwards {
318
+ localAddr , remoteAddr , err := parseRemoteForward (remoteForward )
319
+ if err != nil {
320
+ return err
321
+ }
319
322
320
- closer , err := sshRemoteForward (ctx , inv .Stderr , sshClient , localAddr , remoteAddr )
321
- if err != nil {
322
- return xerrors .Errorf ("ssh remote forward: %w" , err )
323
- }
324
- if err = stack .push ("sshRemoteForward" , closer ); err != nil {
325
- return err
323
+ closer , err := sshRemoteForward (ctx , inv .Stderr , sshClient , localAddr , remoteAddr )
324
+ if err != nil {
325
+ return xerrors .Errorf ("ssh remote forward: %w" , err )
326
+ }
327
+ if err = stack .push ("sshRemoteForward" , closer ); err != nil {
328
+ return err
329
+ }
326
330
}
327
331
}
328
332
@@ -460,7 +464,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
460
464
Description : "Enable remote port forwarding (remote_port:local_address:local_port)." ,
461
465
Env : "CODER_SSH_REMOTE_FORWARD" ,
462
466
FlagShorthand : "R" ,
463
- Value : clibase .StringOf ( & remoteForward ),
467
+ Value : clibase .StringArrayOf ( & remoteForwards ),
464
468
},
465
469
sshDisableAutostartOption (clibase .BoolOf (& disableAutostart )),
466
470
}
0 commit comments