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

Function reloadHosts

cmd/fssh/shell_commands.go:587–636  ·  view source on GitHub ↗

reloadHosts reloads host information into the context

(ctx *ShellContext)

Source from the content-addressed store, hash-verified

585
586// reloadHosts reloads host information into the context
587func reloadHosts(ctx *ShellContext) error {
588 // Reload host infos
589 infos, err := sshconfig.LoadHostInfos()
590 if err != nil {
591 return err
592 }
593
594 // Rebuild all mappings
595 ctx.infos = infos
596 ctx.hosts = make([]string, 0, len(infos))
597 ctx.byName = make(map[string]sshconfig.HostInfo)
598 ctx.byHostname = make(map[string]sshconfig.HostInfo)
599 ctx.ipToName = make(map[string]string)
600 ctx.idToName = make(map[string]string)
601 ctx.hostnames = []string{}
602 ctx.ips = []string{}
603 ctx.ids = []string{}
604
605 for _, hi := range infos {
606 ctx.hosts = append(ctx.hosts, hi.Name)
607 ctx.byName[hi.Name] = hi
608 }
609
610 for _, hi := range infos {
611 hn := displayHostname(hi)
612 if hn != "" {
613 ctx.byHostname[hn] = hi
614 ctx.hostnames = append(ctx.hostnames, hn)
615 }
616 }
617
618 for i, hi := range infos {
619 id := fmt.Sprintf("%d", i+1)
620 ctx.idToName[id] = hi.Name
621 ctx.ids = append(ctx.ids, id)
622 }
623
624 for _, hi := range infos {
625 hn := displayHostname(hi)
626 ip := resolveIPName(hn)
627 if ip != "" {
628 ctx.ips = append(ctx.ips, ip)
629 if _, ok := ctx.ipToName[ip]; !ok {
630 ctx.ipToName[ip] = hi.Name
631 }
632 }
633 }
634
635 return nil
636}
637
638// cmdGlobalShow displays the current Host * configuration
639func cmdGlobalShow(ctx *ShellContext) error {

Callers 3

cmdAddFunction · 0.85
cmdEditFunction · 0.85
cmdDeleteFunction · 0.85

Calls 3

LoadHostInfosFunction · 0.92
displayHostnameFunction · 0.85
resolveIPNameFunction · 0.85

Tested by

no test coverage detected