Skip to content

Commit

Permalink
introduce --no-attach to ignore some service output
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jan 3, 2023
1 parent dcbd68a commit 7a49dcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/compose/up.go
Expand Up @@ -48,6 +48,7 @@ type upOptions struct {
noPrefix bool
attachDependencies bool
attach []string
noAttach []string
timestamp bool
wait bool
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/slices.go
Expand Up @@ -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
}

0 comments on commit 7a49dcd

Please sign in to comment.