mirror of https://github.com/docker/cli.git
Merge pull request #25983 from jhorwit2/jah/ps-refactor
Add -a option to service/node ps
This commit is contained in:
commit
dd33c288ec
|
@ -17,6 +17,7 @@ import (
|
||||||
|
|
||||||
type psOptions struct {
|
type psOptions struct {
|
||||||
nodeIDs []string
|
nodeIDs []string
|
||||||
|
all bool
|
||||||
noResolve bool
|
noResolve bool
|
||||||
noTrunc bool
|
noTrunc bool
|
||||||
filter opts.FilterOpt
|
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.noTrunc, "no-trunc", false, "Do not truncate output")
|
||||||
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
|
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.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
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,11 @@ func runPs(dockerCli *command.DockerCli, opts psOptions) error {
|
||||||
filter := opts.filter.Value()
|
filter := opts.filter.Value()
|
||||||
filter.Add("node", node.ID)
|
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})
|
nodeTasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
|
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
"github.com/docker/docker/cli/command/idresolver"
|
"github.com/docker/docker/cli/command/idresolver"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
|
|
||||||
type psOptions struct {
|
type psOptions struct {
|
||||||
serviceID string
|
serviceID string
|
||||||
|
all bool
|
||||||
quiet bool
|
quiet bool
|
||||||
noResolve bool
|
noResolve bool
|
||||||
noTrunc 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.noTrunc, "no-trunc", false, "Do not truncate output")
|
||||||
flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names")
|
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.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
|
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})
|
tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: filter})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue