Browse Source

feat: add since & until flags to events command

Signed-off-by: MohammadHasan Akbari <[email protected]>
Co-authored-by: Amin Ehterami <[email protected]>
MohammadHasan Akbari 4 months ago
parent
commit
35efa97b7d

+ 7 - 1
cmd/compose/events.go

@@ -29,7 +29,9 @@ import (
 
 type eventsOpts struct {
 	*composeOptions
-	json bool
+	json  bool
+	since string
+	until string
 }
 
 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
 	}
 
 	cmd.Flags().BoolVar(&opts.json, "json", false, "Output events as a stream of json objects")
+	cmd.Flags().StringVar(&opts.since, "since", "", "Show all events created since timestamp")
+	cmd.Flags().StringVar(&opts.until, "until", "", "Stream events until this timestamp")
 	return cmd
 }
 
@@ -59,6 +63,8 @@ func runEvents(ctx context.Context, dockerCli command.Cli, backend api.Service,
 
 	return backend.Events(ctx, name, api.EventsOptions{
 		Services: services,
+		Since:    opts.since,
+		Until:    opts.until,
 		Consumer: func(event api.Event) error {
 			if opts.json {
 				marshal, err := json.Marshal(map[string]interface{}{

+ 6 - 4
docs/reference/compose_events.md

@@ -23,10 +23,12 @@ The events that can be received using this can be seen [here](/reference/cli/doc
 
 ### Options
 
-| Name        | Type   | Default | Description                               |
-|:------------|:-------|:--------|:------------------------------------------|
-| `--dry-run` | `bool` |         | Execute command in dry run mode           |
-| `--json`    | `bool` |         | Output events as a stream of json objects |
+| Name        | Type     | Default | Description                               |
+|:------------|:---------|:--------|:------------------------------------------|
+| `--dry-run` | `bool`   |         | Execute command in dry run mode           |
+| `--json`    | `bool`   |         | Output events as a stream of json objects |
+| `--since`   | `string` |         | Show all events created since timestamp   |
+| `--until`   | `string` |         | Stream events until this timestamp        |
 
 
 <!---MARKER_GEN_END-->

+ 18 - 0
docs/reference/docker_compose_events.yaml

@@ -34,6 +34,24 @@ options:
       experimentalcli: false
       kubernetes: false
       swarm: false
+    - option: since
+      value_type: string
+      description: Show all events created since timestamp
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
+    - option: until
+      value_type: string
+      description: Stream events until this timestamp
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
 inherited_options:
     - option: dry-run
       value_type: bool

+ 2 - 0
pkg/api/api.go

@@ -398,6 +398,8 @@ type AttachOptions struct {
 type EventsOptions struct {
 	Services []string
 	Consumer func(event Event) error
+	Since    string
+	Until    string
 }
 
 // Event is a container runtime event served by Events API

+ 2 - 0
pkg/compose/events.go

@@ -32,6 +32,8 @@ func (s *composeService) Events(ctx context.Context, projectName string, options
 	projectName = strings.ToLower(projectName)
 	evts, errors := s.apiClient().Events(ctx, events.ListOptions{
 		Filters: filters.NewArgs(projectFilter(projectName)),
+		Since:   options.Since,
+		Until:   options.Until,
 	})
 	for {
 		select {