/
login.go
50 lines (42 loc) · 950 Bytes
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"os"
"os/exec"
"path/filepath"
"strconv"
)
type Login struct {
Name string
}
func NewLogin(name string) *Login {
i := Login{
Name: name,
}
return &i
}
func (self *Login) Run() (err error) {
locationPathAbs, _ := filepath.Abs(ConvPath(LocationPath))
var buf bytes.Buffer
buf.WriteString(locationPathAbs)
buf.WriteString(ServerListPath)
list := NewList(buf.String())
buf.Reset()
if list.ExistServer(self.Name) {
server, _ := list.GetServer(self.Name)
var cmd *exec.Cmd
if server.UsePassword {
cmd = exec.Command("ssh", server.Host, "-l", server.LoginUser, "-p", strconv.Itoa(server.Port))
} else {
cmd = exec.Command("ssh", server.Host, "-l", server.LoginUser, "-p", strconv.Itoa(server.Port), "-i", ConvPath(server.IdentityFile))
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
} else {
help := NewHelp()
help.Run()
}
return
}