remote: parse port from user@host:port SSH target

This commit is contained in:
ollie 2026-07-19 19:11:32 +02:00
parent b218706f76
commit 01e97daefc
1 changed files with 10 additions and 1 deletions

View File

@ -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()