MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runStorageList

Function runStorageList

internal/cli/storage.go:92–156  ·  view source on GitHub ↗
(cmd *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

90}
91
92func 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})

Callers

nothing calls this directly

Calls 9

initCLISessionFunction · 0.85
printErrorFunction · 0.85
fetchStorageRowsFunction · 0.85
getOutputFormatFunction · 0.85
formatBytesFunction · 0.85
printTableFunction · 0.85
printJSONFunction · 0.85
clientForNodeMethod · 0.80
getNodesMethod · 0.80

Tested by

no test coverage detected