From e7cbaafa9dc2c5f6103f72e308666ee957221b7b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 20 Mar 2026 09:54:30 +0100 Subject: [PATCH] cli/command/container: statsFormatWrite: inline render func Signed-off-by: Sebastiaan van Stijn --- cli/command/container/formatter_stats.go | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/cli/command/container/formatter_stats.go b/cli/command/container/formatter_stats.go index a7792f2bc8..de8e3e9899 100644 --- a/cli/command/container/formatter_stats.go +++ b/cli/command/container/formatter_stats.go @@ -119,24 +119,15 @@ func NewStats(container string) *Stats { // statsFormatWrite renders the context for a list of containers statistics func statsFormatWrite(ctx formatter.Context, stats []StatsEntry, osType string, trunc bool) error { - render := func(format func(subContext formatter.SubContext) error) error { - for _, cstats := range stats { - statsCtx := &statsContext{ - s: cstats, - os: osType, - trunc: trunc, - } - if err := format(statsCtx); err != nil { - return err - } - } - return nil - } + // TODO(thaJeztah): this should be taken from the (first) StatsEntry instead. + // also, assuming all stats are for the same platform (and basing the + // column headers on that) won't allow aggregated results, which could + // be mixed platform. memUsage := memUseHeader if osType == winOSType { memUsage = winMemUseHeader } - statsCtx := statsContext{} + statsCtx := statsContext{os: osType} statsCtx.Header = formatter.SubHeaderContext{ "Container": containerHeader, "Name": formatter.NameHeader, @@ -148,8 +139,18 @@ func statsFormatWrite(ctx formatter.Context, stats []StatsEntry, osType string, "BlockIO": blockIOHeader, "PIDs": pidsHeader, } - statsCtx.os = osType - return ctx.Write(&statsCtx, render) + return ctx.Write(&statsCtx, func(format func(subContext formatter.SubContext) error) error { + for _, cstats := range stats { + if err := format(&statsContext{ + s: cstats, + os: osType, + trunc: trunc, + }); err != nil { + return err + } + } + return nil + }) } type statsContext struct {