From 7a49dcdb113d2d3d03d3d0017d61f5624538598b Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 3 Jan 2023 15:35:24 +0100 Subject: [PATCH] introduce --no-attach to ignore some service output Signed-off-by: Nicolas De Loof --- cmd/compose/up.go | 3 +++ pkg/utils/slices.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/cmd/compose/up.go b/cmd/compose/up.go index b4ee9357c52..f4bba1cc83a 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -48,6 +48,7 @@ type upOptions struct { noPrefix bool attachDependencies bool attach []string + noAttach []string timestamp bool wait bool } @@ -128,6 +129,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob 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.") + flags.StringArrayVar(&up.noAttach, "no-attach", []string{}, "Don't attach to specified service.") flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.") return upCmd @@ -185,6 +187,7 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create if len(attachTo) == 0 { attachTo = project.ServiceNames() } + attachTo = utils.RemoveAll(attachTo, upOptions.noAttach) create := api.CreateOptions{ Services: services, diff --git a/pkg/utils/slices.go b/pkg/utils/slices.go index 3b635c25db0..8f05aa1b778 100644 --- a/pkg/utils/slices.go +++ b/pkg/utils/slices.go @@ -28,3 +28,14 @@ func Contains[T any](origin []T, element T) bool { } return false } + +// RemoveAll removes all elements from origin slice +func RemoveAll[T any](origin []T, elements []T) []T { + var filtered []T + for _, v := range origin { + if !Contains(elements, v) { + filtered = append(filtered, v) + } + } + return filtered +}