working on remote:new

This commit is contained in:
sawka 2022-09-30 16:23:40 -07:00
parent 62c3390d31
commit 23759b7283
3 changed files with 17 additions and 4 deletions

View File

@ -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"]

View File

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

View File

@ -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 {