From e8666b02f356a2e2549cabc311e5c28e6316a7cb Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 7 Sep 2021 08:24:52 +0200 Subject: [PATCH] introduce up --attach Signed-off-by: Nicolas De Loof --- cmd/compose/up.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 7e31fb23..1d305b31 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -49,6 +49,7 @@ type upOptions struct { noColor bool noPrefix bool attachDependencies bool + attach []string } func (opts upOptions) apply(project *types.Project, services []string) error { @@ -107,8 +108,8 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command { if create.Build && create.noBuild { return fmt.Errorf("--build and --no-build are incompatible") } - if up.Detach && (up.attachDependencies || up.cascadeStop) { - return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit or --attach-dependencies") + if up.Detach && (up.attachDependencies || up.cascadeStop || len(up.attach) > 0) { + return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies") } if create.forceRecreate && create.noRecreate { return fmt.Errorf("--force-recreate and --no-recreate are incompatible") @@ -143,6 +144,7 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command { flags.BoolVarP(&create.noInherit, "renew-anon-volumes", "V", false, "Recreate anonymous volumes instead of retrieving data from the previous containers.") flags.BoolVar(&up.attachDependencies, "attach-dependencies", false, "Attach to dependent containers.") flags.BoolVar(&create.quietPull, "quiet-pull", false, "Pull without printing progress information.") + flags.StringArrayVar(&up.attach, "attach", []string{}, "Attach to service output.") return upCmd } @@ -165,6 +167,9 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions } attachTo := services + if len(upOptions.attach) > 0 { + attachTo = upOptions.attach + } if upOptions.attachDependencies { attachTo = project.ServiceNames() }