newTopCommand creates a new cobra.Command for "docker container top",
(dockerCLI command.Cli)
| 21 | |
| 22 | // newTopCommand creates a new cobra.Command for "docker container top", |
| 23 | func newTopCommand(dockerCLI command.Cli) *cobra.Command { |
| 24 | var opts topOptions |
| 25 | |
| 26 | cmd := &cobra.Command{ |
| 27 | Use: "top CONTAINER [ps OPTIONS]", |
| 28 | Short: "Display the running processes of a container", |
| 29 | Args: cli.RequiresMinArgs(1), |
| 30 | RunE: func(cmd *cobra.Command, args []string) error { |
| 31 | opts.container = args[0] |
| 32 | opts.args = args[1:] |
| 33 | return runTop(cmd.Context(), dockerCLI, &opts) |
| 34 | }, |
| 35 | Annotations: map[string]string{ |
| 36 | "aliases": "docker container top, docker top", |
| 37 | }, |
| 38 | ValidArgsFunction: completion.ContainerNames(dockerCLI, false), |
| 39 | DisableFlagsInUseLine: true, |
| 40 | } |
| 41 | |
| 42 | flags := cmd.Flags() |
| 43 | flags.SetInterspersed(false) |
| 44 | |
| 45 | return cmd |
| 46 | } |
| 47 | |
| 48 | func runTop(ctx context.Context, dockerCli command.Cli, opts *topOptions) error { |
| 49 | procList, err := dockerCli.Client().ContainerTop(ctx, opts.container, client.ContainerTopOptions{ |
no test coverage detected
searching dependent graphs…