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:
parent
5eb472025a
commit
1099d172a2
4 changed files with 35 additions and 6 deletions
|
@ -5,6 +5,7 @@ type APIHistory struct {
|
|||
Tags []string `json:",omitempty"`
|
||||
Created int64
|
||||
CreatedBy string `json:",omitempty"`
|
||||
Size int64
|
||||
}
|
||||
|
||||
type APIImages struct {
|
||||
|
|
34
commands.go
34
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
|
||||
|
|
|
@ -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``
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue