remote: parse port from user@host:port SSH target
This commit is contained in:
parent
b218706f76
commit
01e97daefc
|
|
@ -56,7 +56,16 @@ func Dial(ctx context.Context, cfg Config) (*Server, error) {
|
|||
remoteCmd += " --yolo"
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, "ssh", cfg.SSHTarget, remoteCmd)
|
||||
// Parse optional port from SSHTarget (user@host:port or host:port)
|
||||
sshArgs := []string{}
|
||||
sshTarget := cfg.SSHTarget
|
||||
if host, port, ok := strings.Cut(sshTarget, ":"); ok && port != "" {
|
||||
sshTarget = host
|
||||
sshArgs = append(sshArgs, "-p", port)
|
||||
}
|
||||
sshArgs = append(sshArgs, sshTarget, remoteCmd)
|
||||
|
||||
cmd := exec.CommandContext(ctx, "ssh", sshArgs...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
stdin, err := cmd.StdinPipe()
|
||||
|
|
|
|||
Reference in New Issue