mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
feat: add since & until flags to events command
Signed-off-by: MohammadHasan Akbari <jarqvi.jarqvi@gmail.com> Co-authored-by: Amin Ehterami <A.Ehterami@proton.me>
This commit is contained in:
parent
9e17a091be
commit
35efa97b7d
@ -29,7 +29,9 @@ import (
|
|||||||
|
|
||||||
type eventsOpts struct {
|
type eventsOpts struct {
|
||||||
*composeOptions
|
*composeOptions
|
||||||
json bool
|
json bool
|
||||||
|
since string
|
||||||
|
until string
|
||||||
}
|
}
|
||||||
|
|
||||||
func eventsCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
|
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().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
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +63,8 @@ func runEvents(ctx context.Context, dockerCli command.Cli, backend api.Service,
|
|||||||
|
|
||||||
return backend.Events(ctx, name, api.EventsOptions{
|
return backend.Events(ctx, name, api.EventsOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
|
Since: opts.since,
|
||||||
|
Until: opts.until,
|
||||||
Consumer: func(event api.Event) error {
|
Consumer: func(event api.Event) error {
|
||||||
if opts.json {
|
if opts.json {
|
||||||
marshal, err := json.Marshal(map[string]interface{}{
|
marshal, err := json.Marshal(map[string]interface{}{
|
||||||
|
@ -23,10 +23,12 @@ The events that can be received using this can be seen [here](/reference/cli/doc
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|:------------|:-------|:--------|:------------------------------------------|
|
|:------------|:---------|:--------|:------------------------------------------|
|
||||||
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
||||||
| `--json` | `bool` | | Output events as a stream of json objects |
|
| `--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-->
|
<!---MARKER_GEN_END-->
|
||||||
|
@ -34,6 +34,24 @@ options:
|
|||||||
experimentalcli: false
|
experimentalcli: false
|
||||||
kubernetes: false
|
kubernetes: false
|
||||||
swarm: 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:
|
inherited_options:
|
||||||
- option: dry-run
|
- option: dry-run
|
||||||
value_type: bool
|
value_type: bool
|
||||||
|
@ -398,6 +398,8 @@ type AttachOptions struct {
|
|||||||
type EventsOptions struct {
|
type EventsOptions struct {
|
||||||
Services []string
|
Services []string
|
||||||
Consumer func(event Event) error
|
Consumer func(event Event) error
|
||||||
|
Since string
|
||||||
|
Until string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event is a container runtime event served by Events API
|
// Event is a container runtime event served by Events API
|
||||||
|
@ -32,6 +32,8 @@ func (s *composeService) Events(ctx context.Context, projectName string, options
|
|||||||
projectName = strings.ToLower(projectName)
|
projectName = strings.ToLower(projectName)
|
||||||
evts, errors := s.apiClient().Events(ctx, events.ListOptions{
|
evts, errors := s.apiClient().Events(ctx, events.ListOptions{
|
||||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||||
|
Since: options.Since,
|
||||||
|
Until: options.Until,
|
||||||
})
|
})
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user