Skip to content

Commit 35efa97

Browse files
jarqvismaEti
authored andcommitted
feat: add since & until flags to events command
Signed-off-by: MohammadHasan Akbari <[email protected]> Co-authored-by: Amin Ehterami <[email protected]>
1 parent 9e17a09 commit 35efa97

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

cmd/compose/events.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929

3030
type eventsOpts struct {
3131
*composeOptions
32-
json bool
32+
json bool
33+
since string
34+
until string
3335
}
3436

3537
func eventsCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
@@ -48,6 +50,8 @@ func eventsCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service
4850
}
4951

5052
cmd.Flags().BoolVar(&opts.json, "json", false, "Output events as a stream of json objects")
53+
cmd.Flags().StringVar(&opts.since, "since", "", "Show all events created since timestamp")
54+
cmd.Flags().StringVar(&opts.until, "until", "", "Stream events until this timestamp")
5155
return cmd
5256
}
5357

@@ -59,6 +63,8 @@ func runEvents(ctx context.Context, dockerCli command.Cli, backend api.Service,
5963

6064
return backend.Events(ctx, name, api.EventsOptions{
6165
Services: services,
66+
Since: opts.since,
67+
Until: opts.until,
6268
Consumer: func(event api.Event) error {
6369
if opts.json {
6470
marshal, err := json.Marshal(map[string]interface{}{

docs/reference/compose_events.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ The events that can be received using this can be seen [here](/reference/cli/doc
2323

2424
### Options
2525

26-
| Name | Type | Default | Description |
27-
|:------------|:-------|:--------|:------------------------------------------|
28-
| `--dry-run` | `bool` | | Execute command in dry run mode |
29-
| `--json` | `bool` | | Output events as a stream of json objects |
26+
| Name | Type | Default | Description |
27+
|:------------|:---------|:--------|:------------------------------------------|
28+
| `--dry-run` | `bool` | | Execute command in dry run mode |
29+
| `--json` | `bool` | | Output events as a stream of json objects |
30+
| `--since` | `string` | | Show all events created since timestamp |
31+
| `--until` | `string` | | Stream events until this timestamp |
3032

3133

3234
<!---MARKER_GEN_END-->

docs/reference/docker_compose_events.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ options:
3434
experimentalcli: false
3535
kubernetes: false
3636
swarm: false
37+
- option: since
38+
value_type: string
39+
description: Show all events created since timestamp
40+
deprecated: false
41+
hidden: false
42+
experimental: false
43+
experimentalcli: false
44+
kubernetes: false
45+
swarm: false
46+
- option: until
47+
value_type: string
48+
description: Stream events until this timestamp
49+
deprecated: false
50+
hidden: false
51+
experimental: false
52+
experimentalcli: false
53+
kubernetes: false
54+
swarm: false
3755
inherited_options:
3856
- option: dry-run
3957
value_type: bool

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ type AttachOptions struct {
398398
type EventsOptions struct {
399399
Services []string
400400
Consumer func(event Event) error
401+
Since string
402+
Until string
401403
}
402404

403405
// Event is a container runtime event served by Events API

pkg/compose/events.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func (s *composeService) Events(ctx context.Context, projectName string, options
3232
projectName = strings.ToLower(projectName)
3333
evts, errors := s.apiClient().Events(ctx, events.ListOptions{
3434
Filters: filters.NewArgs(projectFilter(projectName)),
35+
Since: options.Since,
36+
Until: options.Until,
3537
})
3638
for {
3739
select {

0 commit comments

Comments
 (0)