2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-10-20 04:23:32 -04:00
|
|
|
"strconv"
|
2015-07-07 16:10:29 -04:00
|
|
|
"strings"
|
2015-03-24 23:57:23 -04:00
|
|
|
"text/tabwriter"
|
|
|
|
"time"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2015-03-29 17:17:23 -04:00
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
2015-03-24 23:57:23 -04:00
|
|
|
"github.com/docker/docker/pkg/units"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdHistory shows the history of an image.
|
|
|
|
//
|
|
|
|
// Usage: docker history [OPTIONS] IMAGE
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdHistory(args ...string) error {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("history", []string{"IMAGE"}, Cli.DockerCommands["history"].Description, true)
|
2015-04-16 11:29:04 -04:00
|
|
|
human := cmd.Bool([]string{"H", "-human"}, true, "Print sizes and dates in human readable format")
|
2015-03-24 23:57:23 -04:00
|
|
|
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
|
2015-11-09 09:37:24 -05:00
|
|
|
noTrunc := cmd.Bool([]string{"-no-trunc"}, false, "Don't truncate output")
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-07-03 05:26:09 -04:00
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-12-03 14:54:31 -05:00
|
|
|
history, err := cli.client.ImageHistory(cmd.Arg(0))
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
2015-04-16 11:29:04 -04:00
|
|
|
|
2015-10-20 04:23:32 -04:00
|
|
|
if *quiet {
|
|
|
|
for _, entry := range history {
|
2015-04-16 11:29:04 -04:00
|
|
|
if *noTrunc {
|
2015-10-20 04:23:32 -04:00
|
|
|
fmt.Fprintf(w, "%s\n", entry.ID)
|
2015-03-24 23:57:23 -04:00
|
|
|
} else {
|
2015-10-20 04:23:32 -04:00
|
|
|
fmt.Fprintf(w, "%s\n", stringid.TruncateID(entry.ID))
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-10-20 04:23:32 -04:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|
2015-04-16 11:29:04 -04:00
|
|
|
|
2015-11-01 21:27:54 -05:00
|
|
|
var imageID string
|
|
|
|
var createdBy string
|
|
|
|
var created string
|
|
|
|
var size string
|
|
|
|
|
2015-10-20 04:23:32 -04:00
|
|
|
fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
|
|
|
|
for _, entry := range history {
|
2015-11-01 21:27:54 -05:00
|
|
|
imageID = entry.ID
|
|
|
|
createdBy = strings.Replace(entry.CreatedBy, "\t", " ", -1)
|
2015-10-20 04:23:32 -04:00
|
|
|
if *noTrunc == false {
|
|
|
|
createdBy = stringutils.Truncate(createdBy, 45)
|
|
|
|
imageID = stringid.TruncateID(entry.ID)
|
|
|
|
}
|
2015-04-16 11:29:04 -04:00
|
|
|
|
2015-11-01 21:27:54 -05:00
|
|
|
if *human {
|
|
|
|
created = units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))) + " ago"
|
|
|
|
size = units.HumanSize(float64(entry.Size))
|
|
|
|
} else {
|
2015-10-20 04:23:32 -04:00
|
|
|
created = time.Unix(entry.Created, 0).Format(time.RFC3339)
|
|
|
|
size = strconv.FormatInt(entry.Size, 10)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-10-20 04:23:32 -04:00
|
|
|
|
|
|
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", imageID, created, createdBy, size, entry.Comment)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|