diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index f885ff1e..2871ed29 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -563,6 +563,7 @@ func RemoteNewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss } if pk.Kwargs["key"] != "" { keyFile := pk.Kwargs["key"] + keyFile = base.ExpandHomeDir(keyFile) fd, err := os.Open(keyFile) if fd != nil { fd.Close() @@ -572,6 +573,17 @@ func RemoteNewCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss } sshOpts.SSHIdentity = keyFile } + if pk.Kwargs["port"] != "" { + portStr := pk.Kwargs["port"] + portVal, err := strconv.Atoi(portStr) + if err != nil { + return makeRemoteEditErrorReturn(visualEdit, fmt.Errorf("/remote:new invalid port %q: %v", portStr, err)) + } + if portVal <= 0 { + return makeRemoteEditErrorReturn(visualEdit, fmt.Errorf("/remote:new invalid port %d (must be positive)", portVal)) + } + sshOpts.SSHPort = portVal + } remoteOpts := &sstore.RemoteOptsType{} if pk.Kwargs["color"] != "" { color := pk.Kwargs["color"] diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index 65c5c2f7..f3c7cff6 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -123,7 +123,7 @@ func UpsertRemote(ctx context.Context, r *RemoteType) error { if tx.Exists(query, r.RemoteCanonicalName) { return fmt.Errorf("remote has duplicate canonicalname '%s', cannot create", r.RemoteCanonicalName) } - query = `SELECT remoteid FROM remote WHERE alias = ?` + query = `SELECT remoteid FROM remote WHERE remotealias = ?` if r.RemoteAlias != "" && tx.Exists(query, r.RemoteAlias) { return fmt.Errorf("remote has duplicate alias '%s', cannot create", r.RemoteAlias) } diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index 40dcfecc..23ee71f5 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -470,11 +470,12 @@ type LineType struct { } type SSHOpts struct { - Local bool `json:"local"` + Local bool `json:"local,omitempty"` SSHHost string `json:"sshhost"` - SSHOptsStr string `json:"sshopts"` - SSHIdentity string `json:"sshidentity"` SSHUser string `json:"sshuser"` + SSHOptsStr string `json:"sshopts,omitempty"` + SSHIdentity string `json:"sshidentity,omitempty"` + SSHPort int `json:"sshport,omitempty"` } type RemoteOptsType struct {