Revisit logs/up API to pass a LogConsumer vs io.Writer

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-12-07 09:09:12 +01:00
parent 4826d5155a
commit ca123e08eb
No known key found for this signature in database
GPG key ID: 9858809D6F8F6E7E
11 changed files with 112 additions and 99 deletions

View file

@ -18,12 +18,11 @@ package client
import (
"context"
"io"
"github.com/compose-spec/compose-go/types"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/errdefs"
"github.com/compose-spec/compose-go/types"
)
type composeService struct {
@ -45,7 +44,7 @@ func (c *composeService) Create(ctx context.Context, project *types.Project) err
return errdefs.ErrNotImplemented
}
func (c *composeService) Start(ctx context.Context, project *types.Project, w io.Writer) error {
func (c *composeService) Start(ctx context.Context, project *types.Project, consumer compose.LogConsumer) error {
return errdefs.ErrNotImplemented
}
@ -57,7 +56,7 @@ func (c *composeService) Down(context.Context, string) error {
return errdefs.ErrNotImplemented
}
func (c *composeService) Logs(context.Context, string, io.Writer) error {
func (c *composeService) Logs(context.Context, string, compose.LogConsumer) error {
return errdefs.ErrNotImplemented
}

View file

@ -18,7 +18,6 @@ package compose
import (
"context"
"io"
"github.com/compose-spec/compose-go/types"
)
@ -34,13 +33,13 @@ type Service interface {
// Create executes the equivalent to a `compose create`
Create(ctx context.Context, project *types.Project) error
// Start executes the equivalent to a `compose start`
Start(ctx context.Context, project *types.Project, w io.Writer) error
Start(ctx context.Context, project *types.Project, consumer LogConsumer) error
// Up executes the equivalent to a `compose up`
Up(ctx context.Context, project *types.Project, detach bool) error
// Down executes the equivalent to a `compose down`
Down(ctx context.Context, projectName string) error
// Logs executes the equivalent to a `compose logs`
Logs(ctx context.Context, projectName string, w io.Writer) error
Logs(ctx context.Context, projectName string, consumer LogConsumer) error
// Ps executes the equivalent to a `compose ps`
Ps(ctx context.Context, projectName string) ([]ServiceStatus, error)
// List executes the equivalent to a `docker stack ls`
@ -89,3 +88,8 @@ type Stack struct {
Status string
Reason string
}
// LogConsumer is a callback to process log messages from services
type LogConsumer interface {
Log(service, container, message string)
}