/
modify.go
37 lines (31 loc) · 1014 Bytes
/
modify.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
package action
import (
"github.com/chzyer/readline"
"github.com/sakoken/sshh/config"
"github.com/sakoken/sshh/interactive"
)
func Modify(position int) error {
i, _ := interactive.NewEx(&readline.Config{
InterruptPrompt: "\n",
EOFPrompt: "exit",
FuncFilterInputRune: interactive.FilterInput,
})
defer i.Close()
var host = config.SshhData().Connectors[position]
host = host.Clone()
host.Host = i.Question("HostName", true, host.Host)
host.User = i.Question("UserName", false, host.User)
host.Port = i.Question("PortNumber", true, host.Port)
if has, hasHost := config.SshhData().Has(host); has && host.Position != hasHost.Position {
println("\033[31mAlready exists\033[00m")
return nil
}
pswd, _ := i.ServerPassword(false)
if len(pswd) > 0 {
host.Password = pswd
}
//host.Key = Question("SSHKey:", true, host.Key)
host.Explanation = i.Question("Explanation", false, host.Explanation)
config.SshhData().Connectors[position] = host
return config.SshhData().Save()
}