Ver Fonte

Merge pull request #381 from dotcloud/371-add-l-ps

Add options to docker ps
Guillaume J. Charmes há 12 anos atrás
pai
commit
a8c15477d9
1 ficheiros alterados com 10 adições e 2 exclusões
  1. 10 2
      commands.go

+ 10 - 2
commands.go

@@ -659,17 +659,25 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
 	quiet := cmd.Bool("q", false, "Only display numeric IDs")
 	flAll := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
 	flFull := cmd.Bool("notrunc", false, "Don't truncate output")
+	latest := cmd.Bool("l", false, "Show only the latest created container, include non-running ones.")
+	nLast := cmd.Int("n", -1, "Show n last created containers, include non-running ones.")
 	if err := cmd.Parse(args); err != nil {
 		return nil
 	}
+	if *nLast == -1 && *latest {
+		*nLast = 1
+	}
 	w := tabwriter.NewWriter(stdout, 12, 1, 3, ' ', 0)
 	if !*quiet {
 		fmt.Fprintln(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT")
 	}
-	for _, container := range srv.runtime.List() {
-		if !container.State.Running && !*flAll {
+	for i, container := range srv.runtime.List() {
+		if !container.State.Running && !*flAll && *nLast == -1 {
 			continue
 		}
+		if i == *nLast {
+			break
+		}
 		if !*quiet {
 			command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
 			if !*flFull {