(cmd *cobra.Command, _ []string)
| 90 | } |
| 91 | |
| 92 | func runStorageList(cmd *cobra.Command, _ []string) error { |
| 93 | ctx := context.Background() |
| 94 | |
| 95 | session, err := initCLISession(cmd) |
| 96 | if err != nil { |
| 97 | return printError(err) |
| 98 | } |
| 99 | |
| 100 | if session == nil { |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | nodeName, _ := cmd.Flags().GetString("node") |
| 105 | |
| 106 | var rows []storageListRow |
| 107 | |
| 108 | if nodeName != "" { |
| 109 | client, err := session.clientForNode(ctx, nodeName) |
| 110 | if err != nil { |
| 111 | return printError(err) |
| 112 | } |
| 113 | |
| 114 | rows, err = fetchStorageRows(client, nodeName) |
| 115 | if err != nil { |
| 116 | return printError(err) |
| 117 | } |
| 118 | } else { |
| 119 | nodes, err := session.getNodes(ctx) |
| 120 | if err != nil { |
| 121 | return printError(fmt.Errorf("failed to fetch nodes: %w", err)) |
| 122 | } |
| 123 | |
| 124 | for _, node := range nodes { |
| 125 | if node == nil { |
| 126 | continue |
| 127 | } |
| 128 | |
| 129 | client, err := session.clientForNode(ctx, node.Name) |
| 130 | if err != nil { |
| 131 | continue |
| 132 | } |
| 133 | |
| 134 | nodeRows, err := fetchStorageRows(client, node.Name) |
| 135 | if err != nil { |
| 136 | continue |
| 137 | } |
| 138 | |
| 139 | rows = append(rows, nodeRows...) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | format := getOutputFormat(cmd) |
| 144 | if format == outputTable { |
| 145 | headers := []string{"NAME", "NODE", "TYPE", "USED/TOTAL", "CONTENT"} |
| 146 | tableRows := make([][]string, 0, len(rows)) |
| 147 | for _, r := range rows { |
| 148 | usedTotal := fmt.Sprintf("%s/%s", formatBytes(r.Used), formatBytes(r.Total)) |
| 149 | tableRows = append(tableRows, []string{r.Name, r.Node, r.Type, usedTotal, r.Content}) |
nothing calls this directly
no test coverage detected