MCPcopy Index your code
hub / github.com/docker/cli / newStatsCommand

Function newStatsCommand

cli/command/container/stats.go:68–92  ·  view source on GitHub ↗

newStatsCommand creates a new [cobra.Command] for "docker container stats".

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

66
67// newStatsCommand creates a new [cobra.Command] for "docker container stats".
68func 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).

Callers 1

newContainerCommandFunction · 0.85

Calls 1

RunStatsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…