Show rootfs sizes in image list

Replace the noisy rootfs path column in `banger image list` with the current rootfs file size so the table is easier to scan.

Render a ROOTFS SIZE column from the on-disk image size, fall back to `-` when the artifact cannot be statted, and keep the existing image summary output unchanged.

Add CLI coverage for both the formatted size case and the missing-file fallback, then rebuild and check the live command output.
This commit is contained in:
Thales Maciel 2026-03-21 21:55:01 -03:00
parent 14d8563f3c
commit 3b7e77a2de
No known key found for this signature in database
GPG key ID: 33112E6833C34679
2 changed files with 78 additions and 6 deletions

View file

@ -809,12 +809,7 @@ func newImageListCommand() *cobra.Command {
if err != nil {
return err
}
w := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 8, 2, ' ', 0)
fmt.Fprintln(w, "ID\tNAME\tMANAGED\tROOTFS\tCREATED")
for _, image := range result.Images {
fmt.Fprintf(w, "%s\t%s\t%t\t%s\t%s\n", shortID(image.ID), image.Name, image.Managed, image.RootfsPath, relativeTime(image.CreatedAt))
}
return w.Flush()
return printImageListTable(cmd.OutOrStdout(), result.Images)
},
}
}
@ -1318,6 +1313,38 @@ func printImageSummary(out anyWriter, image model.Image) error {
return err
}
func printImageListTable(out anyWriter, images []model.Image) error {
w := tabwriter.NewWriter(out, 0, 8, 2, ' ', 0)
if _, err := fmt.Fprintln(w, "ID\tNAME\tMANAGED\tROOTFS SIZE\tCREATED"); err != nil {
return err
}
for _, image := range images {
if _, err := fmt.Fprintf(
w,
"%s\t%s\t%t\t%s\t%s\n",
shortID(image.ID),
image.Name,
image.Managed,
rootfsSizeLabel(image.RootfsPath),
relativeTime(image.CreatedAt),
); err != nil {
return err
}
}
return w.Flush()
}
func rootfsSizeLabel(path string) string {
info, err := os.Stat(path)
if err != nil {
return "-"
}
if info.Size() <= 0 {
return "0"
}
return model.FormatSizeBytes(info.Size())
}
func printVMPortsTable(out anyWriter, result api.VMPortsResult) error {
type portRow struct {
Proto string