()
| 14 | ) |
| 15 | |
| 16 | func 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 | }() |
no test coverage detected