(cmd *cobra.Command, _ []string)
| 81 | } |
| 82 | |
| 83 | func runNodesList(cmd *cobra.Command, _ []string) error { |
| 84 | session, err := initCLISession(cmd) |
| 85 | if err != nil { |
| 86 | return printError(err) |
| 87 | } |
| 88 | |
| 89 | if session == nil { |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | nodes, err := session.getNodes(context.Background()) |
| 94 | if err != nil { |
| 95 | return printError(fmt.Errorf("failed to fetch nodes: %w", err)) |
| 96 | } |
| 97 | |
| 98 | out := make([]nodeOutput, 0, len(nodes)) |
| 99 | for _, n := range nodes { |
| 100 | if n != nil { |
| 101 | out = append(out, nodeToOutput(n)) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if getOutputFormat(cmd) == outputTable { |
| 106 | headers := []string{"NAME", "IP", "STATUS", "CPU%", "MEM USED", "MEM TOTAL", "UPTIME"} |
| 107 | rows := make([][]string, 0, len(out)) |
| 108 | |
| 109 | for _, n := range out { |
| 110 | rows = append(rows, []string{ |
| 111 | n.Name, |
| 112 | n.IP, |
| 113 | onlineStr(n.Online), |
| 114 | fmt.Sprintf("%.1f%%", n.CPUUsage*100), |
| 115 | formatBytes(int64(n.MemoryUsed)), |
| 116 | formatBytes(int64(n.MemoryTotal)), |
| 117 | formatUptime(n.Uptime), |
| 118 | }) |
| 119 | } |
| 120 | |
| 121 | printTable(headers, rows) |
| 122 | |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | return printJSON(out) |
| 127 | } |
| 128 | |
| 129 | func newNodesShowCmd() *cobra.Command { |
| 130 | return &cobra.Command{ |
nothing calls this directly
no test coverage detected