2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-04-03 11:31:30 -04:00
|
|
|
"encoding/json"
|
2015-03-24 23:57:23 -04:00
|
|
|
"fmt"
|
|
|
|
"text/tabwriter"
|
|
|
|
"time"
|
|
|
|
|
2015-04-03 11:31:30 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
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 {
|
|
|
|
cmd := cli.Subcmd("history", "IMAGE", "Show the history of an image", true)
|
|
|
|
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)
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-04-03 11:31:30 -04:00
|
|
|
rdr, _, err := cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil)
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-04-03 11:31:30 -04:00
|
|
|
history := []types.ImageHistory{}
|
|
|
|
err = json.NewDecoder(rdr).Decode(&history)
|
|
|
|
if err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
|
|
|
if !*quiet {
|
2015-01-04 01:47:01 -05:00
|
|
|
fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE\tCOMMENT")
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
|
2015-04-03 11:31:30 -04:00
|
|
|
for _, entry := range history {
|
|
|
|
if *noTrunc {
|
|
|
|
fmt.Fprintf(w, entry.ID)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, stringid.TruncateID(entry.ID))
|
|
|
|
}
|
2015-03-24 23:57:23 -04:00
|
|
|
if !*quiet {
|
2015-04-03 11:31:30 -04:00
|
|
|
fmt.Fprintf(w, "\t%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(entry.Created, 0))))
|
2015-03-24 23:57:23 -04:00
|
|
|
|
|
|
|
if *noTrunc {
|
2015-04-03 11:31:30 -04:00
|
|
|
fmt.Fprintf(w, "%s\t", entry.CreatedBy)
|
2015-03-24 23:57:23 -04:00
|
|
|
} else {
|
2015-03-29 17:17:23 -04:00
|
|
|
fmt.Fprintf(w, "%s\t", stringutils.Truncate(entry.CreatedBy, 45))
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-01-04 01:47:01 -05:00
|
|
|
fmt.Fprintf(w, "%s\t", units.HumanSize(float64(entry.Size)))
|
2015-04-08 19:43:25 -04:00
|
|
|
fmt.Fprintf(w, "%s", entry.Comment)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-04-03 11:31:30 -04:00
|
|
|
fmt.Fprintf(w, "\n")
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
return nil
|
|
|
|
}
|