Merge pull request #17365 from HuKeping/rework-history

Rework docker cli history
This commit is contained in:
Sebastiaan van Stijn 2015-10-30 10:33:16 +01:00
commit 855487b379
1 changed files with 25 additions and 26 deletions

View File

@ -3,6 +3,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"time" "time"
@ -40,38 +41,36 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
} }
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
if !*quiet {
fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
}
if *quiet {
for _, entry := range history { for _, entry := range history {
if *noTrunc { if *noTrunc {
fmt.Fprintf(w, entry.ID) fmt.Fprintf(w, "%s\n", entry.ID)
} else { } else {
fmt.Fprintf(w, stringid.TruncateID(entry.ID)) fmt.Fprintf(w, "%s\n", stringid.TruncateID(entry.ID))
} }
if !*quiet { }
if *human { w.Flush()
fmt.Fprintf(w, "\t%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0)))) return nil
} else { }
fmt.Fprintf(w, "\t%s\t", time.Unix(entry.Created, 0).Format(time.RFC3339))
} fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
for _, entry := range history {
if *noTrunc { imageID := entry.ID
fmt.Fprintf(w, "%s\t", strings.Replace(entry.CreatedBy, "\t", " ", -1)) createdBy := strings.Replace(entry.CreatedBy, "\t", " ", -1)
} else { if *noTrunc == false {
fmt.Fprintf(w, "%s\t", stringutils.Truncate(strings.Replace(entry.CreatedBy, "\t", " ", -1), 45)) createdBy = stringutils.Truncate(createdBy, 45)
} imageID = stringid.TruncateID(entry.ID)
}
if *human {
fmt.Fprintf(w, "%s\t", units.HumanSize(float64(entry.Size))) created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago"
} else { size := units.HumanSize(float64(entry.Size))
fmt.Fprintf(w, "%d\t", entry.Size) if *human == false {
} created = time.Unix(entry.Created, 0).Format(time.RFC3339)
size = strconv.FormatInt(entry.Size, 10)
fmt.Fprintf(w, "%s", entry.Comment) }
}
fmt.Fprintf(w, "\n") fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", imageID, created, createdBy, size, entry.Comment)
} }
w.Flush() w.Flush()
return nil return nil