Merge pull request #17365 from HuKeping/rework-history
Rework docker cli history
This commit is contained in:
commit
855487b379
|
@ -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 {
|
||||||
|
if *noTrunc {
|
||||||
|
fmt.Fprintf(w, "%s\n", entry.ID)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%s\n", stringid.TruncateID(entry.ID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Flush()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
|
||||||
for _, entry := range history {
|
for _, entry := range history {
|
||||||
if *noTrunc {
|
imageID := entry.ID
|
||||||
fmt.Fprintf(w, entry.ID)
|
createdBy := strings.Replace(entry.CreatedBy, "\t", " ", -1)
|
||||||
} else {
|
if *noTrunc == false {
|
||||||
fmt.Fprintf(w, stringid.TruncateID(entry.ID))
|
createdBy = stringutils.Truncate(createdBy, 45)
|
||||||
|
imageID = stringid.TruncateID(entry.ID)
|
||||||
}
|
}
|
||||||
if !*quiet {
|
|
||||||
if *human {
|
|
||||||
fmt.Fprintf(w, "\t%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))))
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(w, "\t%s\t", time.Unix(entry.Created, 0).Format(time.RFC3339))
|
|
||||||
}
|
|
||||||
|
|
||||||
if *noTrunc {
|
created := units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago"
|
||||||
fmt.Fprintf(w, "%s\t", strings.Replace(entry.CreatedBy, "\t", " ", -1))
|
size := units.HumanSize(float64(entry.Size))
|
||||||
} else {
|
if *human == false {
|
||||||
fmt.Fprintf(w, "%s\t", stringutils.Truncate(strings.Replace(entry.CreatedBy, "\t", " ", -1), 45))
|
created = time.Unix(entry.Created, 0).Format(time.RFC3339)
|
||||||
}
|
size = strconv.FormatInt(entry.Size, 10)
|
||||||
|
|
||||||
if *human {
|
|
||||||
fmt.Fprintf(w, "%s\t", units.HumanSize(float64(entry.Size)))
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(w, "%d\t", entry.Size)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue