From 21096cfc05294f7e34a37c25112b699f564999e5 Mon Sep 17 00:00:00 2001 From: Josh Horwitz Date: Thu, 3 Nov 2016 09:58:45 -0400 Subject: [PATCH] Add -a option to service/node ps Signed-off-by: Josh Horwitz --- command/node/ps.go | 7 +++++++ command/service/ps.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/command/node/ps.go b/command/node/ps.go index a034721d24..8591f04669 100644 --- a/command/node/ps.go +++ b/command/node/ps.go @@ -17,6 +17,7 @@ import ( type psOptions struct { nodeIDs []string + all bool noResolve bool noTrunc bool filter opts.FilterOpt @@ -43,6 +44,7 @@ func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") + flags.BoolVarP(&opts.all, "all", "a", false, "Show all tasks (default shows tasks that are or will be running)") return cmd } @@ -72,6 +74,11 @@ func runPs(dockerCli *command.DockerCli, opts psOptions) error { filter := opts.filter.Value() filter.Add("node", node.ID) + if !opts.all && !filter.Include("desired-state") { + filter.Add("desired-state", string(swarm.TaskStateRunning)) + filter.Add("desired-state", string(swarm.TaskStateAccepted)) + } + nodeTasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) if err != nil { errs = append(errs, err.Error()) diff --git a/command/service/ps.go b/command/service/ps.go index cf94ad7374..0028507c22 100644 --- a/command/service/ps.go +++ b/command/service/ps.go @@ -2,6 +2,7 @@ package service import ( "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/idresolver" @@ -14,6 +15,7 @@ import ( type psOptions struct { serviceID string + all bool quiet bool noResolve bool noTrunc bool @@ -37,6 +39,7 @@ func newPsCommand(dockerCli *command.DockerCli) *cobra.Command { flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") + flags.BoolVarP(&opts.all, "all", "a", false, "Show all tasks (default shows tasks that are or will be running)") return cmd } @@ -64,6 +67,11 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error { } } + if !opts.all && !filter.Include("desired-state") { + filter.Add("desired-state", string(swarm.TaskStateRunning)) + filter.Add("desired-state", string(swarm.TaskStateAccepted)) + } + tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter}) if err != nil { return err