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

Function runEvents

cmd/compose/events.go:59–93  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts eventsOpts, services []string)

Source from the content-addressed store, hash-verified

57}
58
59func runEvents(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts eventsOpts, services []string) error {
60 name, err := opts.toProjectName(ctx, dockerCli)
61 if err != nil {
62 return err
63 }
64
65 backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
66 if err != nil {
67 return err
68 }
69 return backend.Events(ctx, name, api.EventsOptions{
70 Services: services,
71 Since: opts.since,
72 Until: opts.until,
73 Consumer: func(event api.Event) error {
74 if opts.json {
75 marshal, err := json.Marshal(map[string]any{
76 "time": event.Timestamp,
77 "type": "container",
78 "service": event.Service,
79 "id": event.Container,
80 "action": event.Status,
81 "attributes": event.Attributes,
82 })
83 if err != nil {
84 return err
85 }
86 _, _ = fmt.Fprintln(dockerCli.Out(), string(marshal))
87 } else {
88 _, _ = fmt.Fprintln(dockerCli.Out(), event)
89 }
90 return nil
91 },
92 })
93}

Callers 1

eventsCommandFunction · 0.85

Calls 4

NewComposeServiceFunction · 0.92
toProjectNameMethod · 0.80
EventsMethod · 0.65
OutMethod · 0.45

Tested by

no test coverage detected