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:
parent
14d8563f3c
commit
3b7e77a2de
2 changed files with 78 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue