8 "github.com/docker/docker/api/types/image"
9 "github.com/docker/docker/pkg/stringid"
10 "github.com/docker/docker/pkg/stringutils"
11 units "github.com/docker/go-units"
15 defaultHistoryTableFormat = "table {{.ID}}\t{{.CreatedSince}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}"
16 nonHumanHistoryTableFormat = "table {{.ID}}\t{{.CreatedAt}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}"
18 historyIDHeader = "IMAGE"
19 createdByHeader = "CREATED BY"
20 commentHeader = "COMMENT"
23 // NewHistoryFormat returns a format for rendering an HistoryContext
24 func NewHistoryFormat(source string, quiet bool, human bool) Format {
29 return defaultQuietFormat
31 return nonHumanHistoryTableFormat
33 return defaultHistoryTableFormat
40 // HistoryWrite writes the context
41 func HistoryWrite(ctx Context, human bool, histories []image.HistoryResponseItem) error {
42 render := func(format func(subContext subContext) error) error {
43 for _, history := range histories {
44 historyCtx := &historyContext{trunc: ctx.Trunc, h: history, human: human}
45 if err := format(historyCtx); err != nil {
51 historyCtx := &historyContext{}
52 historyCtx.header = map[string]string{
53 "ID": historyIDHeader,
54 "CreatedSince": createdSinceHeader,
55 "CreatedAt": createdAtHeader,
56 "CreatedBy": createdByHeader,
58 "Comment": commentHeader,
60 return ctx.Write(historyCtx, render)
63 type historyContext struct {
67 h image.HistoryResponseItem
70 func (c *historyContext) MarshalJSON() ([]byte, error) {
74 func (c *historyContext) ID() string {
76 return stringid.TruncateID(c.h.ID)
81 func (c *historyContext) CreatedAt() string {
82 return units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0)))
85 func (c *historyContext) CreatedSince() string {
86 created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(c.h.Created, 0)))
87 return created + " ago"
90 func (c *historyContext) CreatedBy() string {
91 createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1)
93 return stringutils.Ellipsis(createdBy, 45)
98 func (c *historyContext) Size() string {
100 return units.HumanSizeWithPrecision(float64(c.h.Size), 3)
102 return strconv.FormatInt(c.h.Size, 10)
105 func (c *historyContext) Comment() string {