Merge pull request #1200 from docker/fix_start_display

Fix compose start display
This commit is contained in:
Guillaume Tardif 2021-01-29 14:17:32 +01:00 committed by GitHub
commit 0c0c0bea6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 21 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/cli/formatter"
)
@ -55,21 +54,22 @@ func runStart(ctx context.Context, opts startOptions, services []string) error {
return err
}
var consumer compose.LogConsumer
if !opts.Detach {
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
}
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
project, err := opts.toProject()
if err != nil {
return "", err
return err
}
err = filter(project, services)
if err != nil {
return "", err
return err
}
return "", c.ComposeService().Start(ctx, project, consumer)
if opts.Detach {
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
return "", c.ComposeService().Start(ctx, project, nil)
})
return err
}
return c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
}

View File

@ -119,21 +119,27 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
}
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
return "", c.ComposeService().Create(ctx, project, compose.CreateOptions{
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
RemoveOrphans: opts.removeOrphans,
Recreate: opts.recreateStrategy(),
})
if err != nil {
return "", err
}
if opts.Detach {
err = c.ComposeService().Start(ctx, project, nil)
}
return "", err
})
if err != nil {
return err
}
var consumer compose.LogConsumer
if !opts.Detach {
consumer = formatter.NewLogConsumer(ctx, os.Stdout)
if opts.Detach {
return nil
}
err = c.ComposeService().Start(ctx, project, consumer)
err = c.ComposeService().Start(ctx, project, formatter.NewLogConsumer(ctx, os.Stdout))
if errors.Is(ctx.Err(), context.Canceled) {
fmt.Println("Gracefully stopping...")
ctx = context.Background()