newStatsCommand creates a new [cobra.Command] for "docker container stats".
(dockerCLI command.Cli)
| 66 | |
| 67 | // newStatsCommand creates a new [cobra.Command] for "docker container stats". |
| 68 | func newStatsCommand(dockerCLI command.Cli) *cobra.Command { |
| 69 | options := StatsOptions{} |
| 70 | |
| 71 | cmd := &cobra.Command{ |
| 72 | Use: "stats [OPTIONS] [CONTAINER...]", |
| 73 | Short: "Display a live stream of container(s) resource usage statistics", |
| 74 | Args: cli.RequiresMinArgs(0), |
| 75 | RunE: func(cmd *cobra.Command, args []string) error { |
| 76 | options.Containers = args |
| 77 | return RunStats(cmd.Context(), dockerCLI, &options) |
| 78 | }, |
| 79 | Annotations: map[string]string{ |
| 80 | "aliases": "docker container stats, docker stats", |
| 81 | }, |
| 82 | ValidArgsFunction: completion.ContainerNames(dockerCLI, false), |
| 83 | DisableFlagsInUseLine: true, |
| 84 | } |
| 85 | |
| 86 | flags := cmd.Flags() |
| 87 | flags.BoolVarP(&options.All, "all", "a", false, "Show all containers (default shows just running)") |
| 88 | flags.BoolVar(&options.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result") |
| 89 | flags.BoolVar(&options.NoTrunc, "no-trunc", false, "Do not truncate output") |
| 90 | flags.StringVar(&options.Format, "format", "", flagsHelper.FormatHelp) |
| 91 | return cmd |
| 92 | } |
| 93 | |
| 94 | // acceptedStatsFilters is the list of filters accepted by [RunStats] (through |
| 95 | // the [StatsOptions.Filters] option). |
no test coverage detected
searching dependent graphs…