MCPcopy
hub / github.com/docker/compose / statsCommand

Function statsCommand

cmd/compose/stats.go:39–63  ·  view source on GitHub ↗
(p *ProjectOptions, dockerCli command.Cli)

Source from the content-addressed store, hash-verified

37}
38
39func statsCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
40 opts := statsOptions{
41 ProjectOptions: p,
42 }
43 cmd := &cobra.Command{
44 Use: "stats [OPTIONS] [SERVICE]",
45 Short: "Display a live stream of container(s) resource usage statistics",
46 Args: cobra.MaximumNArgs(1),
47 RunE: Adapt(func(ctx context.Context, args []string) error {
48 return runStats(ctx, dockerCli, opts, args)
49 }),
50 ValidArgsFunction: completeServiceNames(dockerCli, p),
51 }
52 flags := cmd.Flags()
53 flags.BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)")
54 flags.StringVar(&opts.format, "format", "", `Format output using a custom template:
55'table': Print output in table format with column headers (default)
56'table TEMPLATE': Print output in table format using the given Go template
57'json': Print in JSON format
58'TEMPLATE': Print output using the given Go template.
59Refer to https://docs.docker.com/engine/cli/formatting/ for more information about formatting output with templates`)
60 flags.BoolVar(&opts.noStream, "no-stream", false, "Disable streaming stats and only pull the first result")
61 flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output")
62 return cmd
63}
64
65func runStats(ctx context.Context, dockerCli command.Cli, opts statsOptions, service []string) error {
66 name, err := opts.ProjectOptions.toProjectName(ctx, dockerCli)

Callers 1

RootCommandFunction · 0.85

Calls 3

AdaptFunction · 0.85
runStatsFunction · 0.85
completeServiceNamesFunction · 0.85

Tested by

no test coverage detected