@@ -37,6 +37,7 @@ import (
3737 "github.com/docker/cli/cli-plugins/manager"
3838 "github.com/docker/cli/cli/command"
3939 "github.com/docker/compose/v2/cmd/formatter"
40+ "github.com/docker/compose/v2/internal/desktop"
4041 "github.com/docker/compose/v2/internal/tracing"
4142 "github.com/docker/compose/v2/pkg/api"
4243 "github.com/docker/compose/v2/pkg/compose"
@@ -365,11 +366,17 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
365366 }
366367 },
367368 PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
369+ ctx := cmd .Context ()
370+
371+ // (1) process env vars
368372 err := setEnvWithDotEnv (& opts )
369373 if err != nil {
370374 return err
371375 }
372376 parent := cmd .Root ()
377+
378+ // (2) call parent pre-run
379+ // TODO(milas): this seems incorrect, remove or document
373380 if parent != nil {
374381 parentPrerun := parent .PersistentPreRunE
375382 if parentPrerun != nil {
@@ -379,21 +386,21 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
379386 }
380387 }
381388 }
389+
390+ // (3) set up display/output
391+ if verbose {
392+ logrus .SetLevel (logrus .TraceLevel )
393+ }
382394 if noAnsi {
383395 if ansi != "auto" {
384396 return errors .New (`cannot specify DEPRECATED "--no-ansi" and "--ansi". Please use only "--ansi"` )
385397 }
386398 ansi = "never"
387399 fmt .Fprint (os .Stderr , "option '--no-ansi' is DEPRECATED ! Please use '--ansi' instead.\n " )
388400 }
389- if verbose {
390- logrus .SetLevel (logrus .TraceLevel )
391- }
392-
393401 if v , ok := os .LookupEnv ("COMPOSE_ANSI" ); ok && ! cmd .Flags ().Changed ("ansi" ) {
394402 ansi = v
395403 }
396-
397404 formatter .SetANSIMode (dockerCli , ansi )
398405
399406 if noColor , ok := os .LookupEnv ("NO_COLOR" ); ok && noColor != "" {
@@ -430,6 +437,7 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
430437 return fmt .Errorf ("unsupported --progress value %q" , opts .Progress )
431438 }
432439
440+ // (4) options validation / normalization
433441 if opts .WorkDir != "" {
434442 if opts .ProjectDir != "" {
435443 return errors .New (`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead` )
@@ -466,13 +474,26 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //
466474 parallel = i
467475 }
468476 if parallel > 0 {
477+ logrus .Debugf ("Limiting max concurrency to %d jobs" , parallel )
469478 backend .MaxConcurrency (parallel )
470479 }
471- ctx , err := backend .DryRunMode (cmd .Context (), dryRun )
480+
481+ // (5) dry run detection
482+ ctx , err = backend .DryRunMode (ctx , dryRun )
472483 if err != nil {
473484 return err
474485 }
475486 cmd .SetContext (ctx )
487+
488+ // (6) Desktop integration
489+ if db , ok := backend .(desktop.IntegrationService ); ok {
490+ if err := db .MaybeEnableDesktopIntegration (ctx ); err != nil {
491+ // not fatal, Compose will still work but behave as though
492+ // it's not running as part of Docker Desktop
493+ logrus .Debugf ("failed to enable Docker Desktop integration: %v" , err )
494+ }
495+ }
496+
476497 return nil
477498 },
478499 }
0 commit comments