(dockerCLI command.Cli)
| 23 | } |
| 24 | |
| 25 | func newPsCommand(dockerCLI command.Cli) *cobra.Command { |
| 26 | options := psOptions{filter: opts.NewFilterOpt()} |
| 27 | |
| 28 | cmd := &cobra.Command{ |
| 29 | Use: "ps [OPTIONS] [NODE...]", |
| 30 | Short: "List tasks running on one or more nodes, defaults to current node", |
| 31 | Args: cli.RequiresMinArgs(0), |
| 32 | RunE: func(cmd *cobra.Command, args []string) error { |
| 33 | options.nodeIDs = []string{"self"} |
| 34 | |
| 35 | if len(args) != 0 { |
| 36 | options.nodeIDs = args |
| 37 | } |
| 38 | |
| 39 | return runPs(cmd.Context(), dockerCLI, options) |
| 40 | }, |
| 41 | ValidArgsFunction: completeNodeNames(dockerCLI), |
| 42 | DisableFlagsInUseLine: true, |
| 43 | } |
| 44 | flags := cmd.Flags() |
| 45 | flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate output") |
| 46 | flags.BoolVar(&options.noResolve, "no-resolve", false, "Do not map IDs to Names") |
| 47 | flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") |
| 48 | flags.StringVar(&options.format, "format", "", "Pretty-print tasks using a Go template") |
| 49 | flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display task IDs") |
| 50 | |
| 51 | return cmd |
| 52 | } |
| 53 | |
| 54 | func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error { |
| 55 | apiClient := dockerCLI.Client() |
searching dependent graphs…