1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add flags to history, add size flag

This commit is contained in:
Travis Cline 2013-10-18 18:39:40 -05:00
parent 5eb472025a
commit 1099d172a2
4 changed files with 35 additions and 6 deletions

View file

@ -5,6 +5,7 @@ type APIHistory struct {
Tags []string `json:",omitempty"` Tags []string `json:",omitempty"`
Created int64 Created int64
CreatedBy string `json:",omitempty"` CreatedBy string `json:",omitempty"`
Size int64
} }
type APIImages struct { type APIImages struct {

View file

@ -788,7 +788,10 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
} }
func (cli *DockerCli) CmdHistory(args ...string) error { func (cli *DockerCli) CmdHistory(args ...string) error {
cmd := Subcmd("history", "IMAGE", "Show the history of an image") cmd := Subcmd("history", "[OPTIONS] IMAGE", "Show the history of an image")
quiet := cmd.Bool("q", false, "only show numeric IDs")
noTrunc := cmd.Bool("notrunc", false, "Don't truncate output")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
return nil return nil
} }
@ -807,14 +810,35 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
if err != nil { if err != nil {
return err return err
} }
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
fmt.Fprintln(w, "ID\tCREATED\tCREATED BY") if !*quiet {
fmt.Fprintln(w, "ID\tCREATED\tCREATED BY\tSIZE")
}
for _, out := range outs { for _, out := range outs {
if out.Tags != nil { if !*quiet {
out.ID = out.Tags[0] if *noTrunc {
fmt.Fprintf(w, "%s\t", out.ID)
} else {
fmt.Fprintf(w, "%s\t", utils.TruncateID(out.ID))
}
fmt.Fprintf(w, "%s ago\t", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
if *noTrunc {
fmt.Fprintf(w, "%s\t", out.CreatedBy)
} else {
fmt.Fprintf(w, "%s\t", utils.Trunc(out.CreatedBy, 45))
}
fmt.Fprintf(w, "%s\n", utils.HumanSize(out.Size))
} else {
if *noTrunc {
fmt.Fprintln(w, out.ID)
} else {
fmt.Fprintln(w, utils.TruncateID(out.ID))
}
} }
fmt.Fprintf(w, "%s \t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
} }
w.Flush() w.Flush()
return nil return nil

View file

@ -282,6 +282,9 @@ Shell 1: (Again .. now showing events)
Show the history of an image Show the history of an image
-notrunc=false: Don't truncate output
-q=false: only show numeric IDs
.. _cli_images: .. _cli_images:
``images`` ``images``

View file

@ -320,10 +320,11 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
outs := []APIHistory{} //produce [] when empty instead of 'null' outs := []APIHistory{} //produce [] when empty instead of 'null'
err = image.WalkHistory(func(img *Image) error { err = image.WalkHistory(func(img *Image) error {
var out APIHistory var out APIHistory
out.ID = srv.runtime.repositories.ImageName(img.ShortID()) out.ID = img.ID
out.Created = img.Created.Unix() out.Created = img.Created.Unix()
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ") out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
out.Tags = lookupMap[img.ID] out.Tags = lookupMap[img.ID]
out.Size = img.Size
outs = append(outs, out) outs = append(outs, out)
return nil return nil
}) })