From 1099d172a2f083c456c3564d403e666e965a9544 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Fri, 18 Oct 2013 18:39:40 -0500 Subject: [PATCH] Add flags to history, add size flag --- api_params.go | 1 + commands.go | 34 +++++++++++++++++++++++++++----- docs/sources/commandline/cli.rst | 3 +++ server.go | 3 ++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/api_params.go b/api_params.go index 40738f9fe9..3c53d0f2aa 100644 --- a/api_params.go +++ b/api_params.go @@ -5,6 +5,7 @@ type APIHistory struct { Tags []string `json:",omitempty"` Created int64 CreatedBy string `json:",omitempty"` + Size int64 } type APIImages struct { diff --git a/commands.go b/commands.go index 4a7c4b8d23..c9b4eddafb 100644 --- a/commands.go +++ b/commands.go @@ -788,7 +788,10 @@ func (cli *DockerCli) CmdRmi(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 { return nil } @@ -807,14 +810,35 @@ func (cli *DockerCli) CmdHistory(args ...string) error { if err != nil { return err } + 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 { - if out.Tags != nil { - out.ID = out.Tags[0] + if !*quiet { + 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() return nil diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index 6efa9b1ebb..cac7178cab 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -282,6 +282,9 @@ Shell 1: (Again .. now showing events) Show the history of an image + -notrunc=false: Don't truncate output + -q=false: only show numeric IDs + .. _cli_images: ``images`` diff --git a/server.go b/server.go index d9e5bc0295..6f28e0e023 100644 --- a/server.go +++ b/server.go @@ -320,10 +320,11 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) { outs := []APIHistory{} //produce [] when empty instead of 'null' err = image.WalkHistory(func(img *Image) error { var out APIHistory - out.ID = srv.runtime.repositories.ImageName(img.ShortID()) + out.ID = img.ID out.Created = img.Created.Unix() out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ") out.Tags = lookupMap[img.ID] + out.Size = img.Size outs = append(outs, out) return nil })