MCPcopy Create free account
hub / github.com/Mister-leo/fssh / runShell

Function runShell

cmd/fssh/shell.go:16–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func runShell() {
17 infos, err := sshconfig.LoadHostInfos()
18 if err != nil {
19 fatal(err)
20 }
21
22 // Load imported keys
23 importedKeys, _ := listImportedKeys()
24
25 // Create context with all mappings
26 ctx := &ShellContext{
27 infos: infos,
28 hosts: make([]string, 0, len(infos)),
29 byName: make(map[string]sshconfig.HostInfo),
30 byHostname: make(map[string]sshconfig.HostInfo),
31 ipToName: make(map[string]string),
32 idToName: make(map[string]string),
33 hostnames: make([]string, 0, len(infos)),
34 ips: make([]string, 0, len(infos)),
35 ids: make([]string, 0, len(infos)),
36 importedKeys: importedKeys,
37 }
38
39 for _, hi := range infos {
40 ctx.hosts = append(ctx.hosts, hi.Name)
41 ctx.byName[hi.Name] = hi
42 }
43 for _, hi := range infos {
44 hn := displayHostname(hi)
45 if hn != "" {
46 ctx.byHostname[hn] = hi
47 ctx.hostnames = append(ctx.hostnames, hn)
48 }
49 }
50 for i, hi := range infos {
51 id := strconv.Itoa(i + 1)
52 ctx.idToName[id] = hi.Name
53 ctx.ids = append(ctx.ids, id)
54 }
55 for _, hi := range infos {
56 hn := displayHostname(hi)
57 ip := resolveIPName(hn)
58 if ip != "" {
59 ctx.ips = append(ctx.ips, ip)
60 if _, ok := ctx.ipToName[ip]; !ok {
61 ctx.ipToName[ip] = hi.Name
62 }
63 }
64 }
65
66 commands := []string{"list", "search", "connect", "add", "edit", "delete", "show", "info", "global", "suspend", "help", "exit", "quit"}
67 l := setupLiner(commands, ctx.hosts, ctx.hostnames, ctx.ips, ctx.ids)
68 ctx.liner = l
69 defer func() {
70 if l != nil {
71 l.Close()
72 }
73 }()

Callers 1

mainFunction · 0.85

Calls 12

LoadHostInfosFunction · 0.92
fatalFunction · 0.85
listImportedKeysFunction · 0.85
displayHostnameFunction · 0.85
resolveIPNameFunction · 0.85
setupLinerFunction · 0.85
cmdAddFunction · 0.85
cmdEditFunction · 0.85
cmdDeleteFunction · 0.85
cmdShowFunction · 0.85
cmdInfoFunction · 0.85
cmdGlobalFunction · 0.85

Tested by

no test coverage detected