From 5a3236d9e8ee8c0051c0cc758ec359fa089b3291 Mon Sep 17 00:00:00 2001 From: Hu Keping Date: Mon, 2 Nov 2015 10:27:54 +0800 Subject: [PATCH] Update logic of history Signed-off-by: Hu Keping --- api/client/history.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/client/history.go b/api/client/history.go index 5230369260..37472bad74 100644 --- a/api/client/history.go +++ b/api/client/history.go @@ -54,18 +54,24 @@ func (cli *DockerCli) CmdHistory(args ...string) error { return nil } + var imageID string + var createdBy string + var created string + var size string + fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT") for _, entry := range history { - imageID := entry.ID - createdBy := strings.Replace(entry.CreatedBy, "\t", " ", -1) + imageID = entry.ID + createdBy = strings.Replace(entry.CreatedBy, "\t", " ", -1) if *noTrunc == false { createdBy = stringutils.Truncate(createdBy, 45) imageID = stringid.TruncateID(entry.ID) } - created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago" - size := units.HumanSize(float64(entry.Size)) - if *human == false { + if *human { + created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago" + size = units.HumanSize(float64(entry.Size)) + } else { created = time.Unix(entry.Created, 0).Format(time.RFC3339) size = strconv.FormatInt(entry.Size, 10) }