Add -a option to service/node ps

Signed-off-by: Josh Horwitz <horwitzja@gmail.com>
This commit is contained in:
Josh Horwitz 2016-11-03 09:58:45 -04:00
parent ee42b42f3c
commit 21096cfc05
2 changed files with 15 additions and 0 deletions

View File

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

View File

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