Skip to content

Commit 8cb8056

Browse files
committed
cli/command/image: historyWrite: inline vars and use struct literals
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7589722 commit 8cb8056

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

cli/command/image/formatter_history.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,30 @@ func HistoryWrite(fmtCtx formatter.Context, human bool, histories []image.Histor
5151

5252
// historyWrite writes the context
5353
func historyWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
54-
render := func(format func(subContext formatter.SubContext) error) error {
54+
historyCtx := &historyContext{
55+
HeaderContext: formatter.HeaderContext{
56+
Header: formatter.SubHeaderContext{
57+
"ID": historyIDHeader,
58+
"CreatedSince": formatter.CreatedSinceHeader,
59+
"CreatedAt": formatter.CreatedAtHeader,
60+
"CreatedBy": createdByHeader,
61+
"Size": formatter.SizeHeader,
62+
"Comment": commentHeader,
63+
},
64+
},
65+
}
66+
return fmtCtx.Write(historyCtx, func(format func(subContext formatter.SubContext) error) error {
5567
for _, history := range histories {
56-
historyCtx := &historyContext{trunc: fmtCtx.Trunc, h: history, human: human}
57-
if err := format(historyCtx); err != nil {
68+
if err := format(&historyContext{
69+
trunc: fmtCtx.Trunc,
70+
h: history,
71+
human: human,
72+
}); err != nil {
5873
return err
5974
}
6075
}
6176
return nil
62-
}
63-
historyCtx := &historyContext{}
64-
historyCtx.Header = formatter.SubHeaderContext{
65-
"ID": historyIDHeader,
66-
"CreatedSince": formatter.CreatedSinceHeader,
67-
"CreatedAt": formatter.CreatedAtHeader,
68-
"CreatedBy": createdByHeader,
69-
"Size": formatter.SizeHeader,
70-
"Comment": commentHeader,
71-
}
72-
return fmtCtx.Write(historyCtx, render)
77+
})
7378
}
7479

7580
type historyContext struct {

0 commit comments

Comments
 (0)