Переглянути джерело

Merge pull request #17602 from HuKeping/update-history

Update logic of history
Vincent Demeester 9 роки тому
батько
коміт
38d3fc00d3
1 змінених файлів з 11 додано та 5 видалено
  1. 11 5
      api/client/history.go

+ 11 - 5
api/client/history.go

@@ -54,18 +54,24 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
 		return nil
 		return nil
 	}
 	}
 
 
+	var imageID string
+	var createdBy string
+	var created string
+	var size string
+
 	fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
 	fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
 	for _, entry := range history {
 	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 {
 		if *noTrunc == false {
 			createdBy = stringutils.Truncate(createdBy, 45)
 			createdBy = stringutils.Truncate(createdBy, 45)
 			imageID = stringid.TruncateID(entry.ID)
 			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)
 			created = time.Unix(entry.Created, 0).Format(time.RFC3339)
 			size = strconv.FormatInt(entry.Size, 10)
 			size = strconv.FormatInt(entry.Size, 10)
 		}
 		}