(ctx *cli.Context)
| 48 | } |
| 49 | |
| 50 | func hostsAction(ctx *cli.Context) error { |
| 51 | if err := errs.NumberOfArguments(ctx, 0); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | // Prepare retry function |
| 56 | retryFunc, err := loginOnUnauthorized(ctx) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | // Initialize CA client with login if needed. |
| 62 | client, err := cautils.NewClient(ctx, ca.WithRetryFunc(retryFunc)) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | resp, err := client.SSHGetHosts() |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | w := new(tabwriter.Writer) |
| 73 | // Format in tab-separated columns with a tab stop of 8. |
| 74 | w.Init(os.Stdout, 0, 8, 1, '\t', 0) |
| 75 | |
| 76 | fmt.Fprintln(w, "HOSTNAME\tID\tTAGS") |
| 77 | for _, h := range resp.Hosts { |
| 78 | tags := "" |
| 79 | for i, ht := range h.HostTags { |
| 80 | if i > 0 { |
| 81 | tags += "," |
| 82 | } |
| 83 | tags += ht.Name + "=" + ht.Value |
| 84 | } |
| 85 | fmt.Fprintf(w, "%s\t%s\t%s\n", h.Hostname, h.HostID, tags) |
| 86 | } |
| 87 | w.Flush() |
| 88 | return nil |
| 89 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…