@@ -119,24 +119,15 @@ func NewStats(container string) *Stats {
119119
120120// statsFormatWrite renders the context for a list of containers statistics
121121func statsFormatWrite (ctx formatter.Context , stats []StatsEntry , osType string , trunc bool ) error {
122- render := func (format func (subContext formatter.SubContext ) error ) error {
123- for _ , cstats := range stats {
124- statsCtx := & statsContext {
125- s : cstats ,
126- os : osType ,
127- trunc : trunc ,
128- }
129- if err := format (statsCtx ); err != nil {
130- return err
131- }
132- }
133- return nil
134- }
122+ // TODO(thaJeztah): this should be taken from the (first) StatsEntry instead.
123+ // also, assuming all stats are for the same platform (and basing the
124+ // column headers on that) won't allow aggregated results, which could
125+ // be mixed platform.
135126 memUsage := memUseHeader
136127 if osType == winOSType {
137128 memUsage = winMemUseHeader
138129 }
139- statsCtx := statsContext {}
130+ statsCtx := statsContext {os : osType }
140131 statsCtx .Header = formatter.SubHeaderContext {
141132 "Container" : containerHeader ,
142133 "Name" : formatter .NameHeader ,
@@ -148,8 +139,18 @@ func statsFormatWrite(ctx formatter.Context, stats []StatsEntry, osType string,
148139 "BlockIO" : blockIOHeader ,
149140 "PIDs" : pidsHeader ,
150141 }
151- statsCtx .os = osType
152- return ctx .Write (& statsCtx , render )
142+ return ctx .Write (& statsCtx , func (format func (subContext formatter.SubContext ) error ) error {
143+ for _ , cstats := range stats {
144+ if err := format (& statsContext {
145+ s : cstats ,
146+ os : osType ,
147+ trunc : trunc ,
148+ }); err != nil {
149+ return err
150+ }
151+ }
152+ return nil
153+ })
153154}
154155
155156type statsContext struct {
0 commit comments