@@ -21,9 +21,8 @@ import (
2121 "fmt"
2222 "time"
2323
24- "github.com/docker/compose/v2/cmd/formatter"
25-
2624 "github.com/compose-spec/compose-go/types"
25+ "github.com/docker/compose/v2/cmd/formatter"
2726 "github.com/spf13/cobra"
2827
2928 "github.com/docker/compose/v2/pkg/api"
@@ -164,17 +163,31 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
164163 consumer = formatter .NewLogConsumer (ctx , streams .Out (), streams .Err (), ! upOptions .noColor , ! upOptions .noPrefix , upOptions .timestamp )
165164 }
166165
167- attachTo := services
166+ attachTo := utils. Set [ string ]{}
168167 if len (upOptions .attach ) > 0 {
169- attachTo = upOptions .attach
168+ attachTo . AddAll ( upOptions .attach ... )
170169 }
171170 if upOptions .attachDependencies {
172- attachTo = project .ServiceNames ()
171+ if err := project .WithServices (attachTo .Elements (), func (s types.ServiceConfig ) error {
172+ if s .Attach == nil || * s .Attach {
173+ attachTo .Add (s .Name )
174+ }
175+ return nil
176+ }); err != nil {
177+ return err
178+ }
173179 }
174180 if len (attachTo ) == 0 {
175- attachTo = project .ServiceNames ()
181+ if err := project .WithServices (services , func (s types.ServiceConfig ) error {
182+ if s .Attach == nil || * s .Attach {
183+ attachTo .Add (s .Name )
184+ }
185+ return nil
186+ }); err != nil {
187+ return err
188+ }
176189 }
177- attachTo = utils . Remove ( attachTo , upOptions .noAttach ... )
190+ attachTo . RemoveAll ( upOptions .noAttach ... )
178191
179192 create := api.CreateOptions {
180193 Services : services ,
@@ -198,7 +211,7 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
198211 Start : api.StartOptions {
199212 Project : project ,
200213 Attach : consumer ,
201- AttachTo : attachTo ,
214+ AttachTo : attachTo . Elements () ,
202215 ExitCodeFrom : upOptions .exitCodeFrom ,
203216 CascadeStop : upOptions .cascadeStop ,
204217 Wait : upOptions .wait ,
0 commit comments