浏览代码

Add flags to history, add size flag

Travis Cline 11 年之前
父节点
当前提交
1099d172a2
共有 4 个文件被更改,包括 35 次插入6 次删除
  1. 1 0
      api_params.go
  2. 29 5
      commands.go
  3. 3 0
      docs/sources/commandline/cli.rst
  4. 2 1
      server.go

+ 1 - 0
api_params.go

@@ -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 {

+ 29 - 5
commands.go

@@ -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 {
-			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()
 	w.Flush()
 	return nil
 	return nil

+ 3 - 0
docs/sources/commandline/cli.rst

@@ -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``

+ 2 - 1
server.go

@@ -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
 	})
 	})