(dockerCLI command.Cli)
| 25 | } |
| 26 | |
| 27 | func newPsCommand(dockerCLI command.Cli) *cobra.Command { |
| 28 | opts := psOptions{filter: cliopts.NewFilterOpt()} |
| 29 | |
| 30 | cmd := &cobra.Command{ |
| 31 | Use: "ps [OPTIONS] STACK", |
| 32 | Short: "List the tasks in the stack", |
| 33 | Args: cli.ExactArgs(1), |
| 34 | RunE: func(cmd *cobra.Command, args []string) error { |
| 35 | opts.namespace = args[0] |
| 36 | if err := validateStackName(opts.namespace); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | return runPS(cmd.Context(), dockerCLI, opts) |
| 40 | }, |
| 41 | ValidArgsFunction: completeNames(dockerCLI), |
| 42 | DisableFlagsInUseLine: true, |
| 43 | } |
| 44 | flags := cmd.Flags() |
| 45 | flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") |
| 46 | flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names") |
| 47 | flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided") |
| 48 | flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display task IDs") |
| 49 | flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) |
| 50 | return cmd |
| 51 | } |
| 52 | |
| 53 | // runPS is the swarm implementation of docker stack ps |
| 54 | func runPS(ctx context.Context, dockerCLI command.Cli, opts psOptions) error { |
searching dependent graphs…