From 8c3331dc978e3cbbe3255a436c8f18f01158eb27 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 10 Apr 2013 19:30:57 +0200 Subject: [PATCH 1/3] add -l to docker ps --- commands.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index 20d6b45c97..a231632f27 100644 --- a/commands.go +++ b/commands.go @@ -647,17 +647,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.") + n_last := cmd.Int("last", -1, "Show last created containers, include non-running ones.") if err := cmd.Parse(args); err != nil { return nil } + if *n_last == -1 && *latest { + *n_last = 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 && *n_last == -1{ continue } + if i == *n_last { + break + } if !*quiet { command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " ")) if !*flFull { From 8bd192fb16a5ac9836d4b1d3df037af65b61ffce Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 10 Apr 2013 21:09:21 +0200 Subject: [PATCH 2/3] changed last to n --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index a231632f27..cc123b44a2 100644 --- a/commands.go +++ b/commands.go @@ -648,7 +648,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) 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.") - n_last := cmd.Int("last", -1, "Show last created containers, include non-running ones.") + n_last := cmd.Int("n", -1, "Show n last created containers, include non-running ones.") if err := cmd.Parse(args); err != nil { return nil } From 17136d58f29fdd921d41ebd7c67c73bd4078b023 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 11 Apr 2013 13:09:40 +0200 Subject: [PATCH 3/3] snake_case to camelCase --- commands.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index cc123b44a2..67689dda82 100644 --- a/commands.go +++ b/commands.go @@ -648,22 +648,22 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) 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.") - n_last := cmd.Int("n", -1, "Show n last created containers, 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 *n_last == -1 && *latest { - *n_last = 1 + 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 i, container := range srv.runtime.List() { - if !container.State.Running && !*flAll && *n_last == -1{ + if !container.State.Running && !*flAll && *nLast == -1 { continue } - if i == *n_last { + if i == *nLast { break } if !*quiet {