Merge pull request #12430 from icecrime/11551_carry

Add -H|--human command-line flag to `docker history`
This commit is contained in:
Jessie Frazelle 2015-04-20 17:28:24 -07:00
commit 47b703593e
3 changed files with 17 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
// Usage: docker history [OPTIONS] IMAGE
func (cli *DockerCli) CmdHistory(args ...string) error {
cmd := cli.Subcmd("history", "IMAGE", "Show the history of an image", true)
human := cmd.Bool([]string{"H", "-human"}, true, "Print sizes and dates in human readable format")
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
cmd.Require(flag.Exact, 1)
@ -46,14 +47,24 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
fmt.Fprintf(w, stringid.TruncateID(entry.ID))
}
if !*quiet {
fmt.Fprintf(w, "\t%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))))
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 {
fmt.Fprintf(w, "%s\t", entry.CreatedBy)
} else {
fmt.Fprintf(w, "%s\t", stringutils.Truncate(entry.CreatedBy, 45))
}
fmt.Fprintf(w, "%s\t", units.HumanSize(float64(entry.Size)))
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")

View File

@ -19,6 +19,9 @@ Show the history of when and how an image was created.
**--help**
Print usage statement
**-H**. **--human**=*true*|*false*
Print sizes and dates in human readable format. The default is *true*.
**--no-trunc**=*true*|*false*
Don't truncate output. The default is *false*.

View File

@ -1222,6 +1222,7 @@ This will create a new Bash session in the container `ubuntu_bash`.
Show the history of an image
-H, --human=true Print sizes and dates in human readable format
--no-trunc=false Don't truncate output
-q, --quiet=false Only show numeric IDs