Repository: docker/compose
File: cmd/compose/up.go (Go)

Code before:
			return err
		}
		err = setServiceScale(project, name, uint64(replicas))
		if err != nil {
			return err
		}
	}

	return nil
}

func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
	up := upOptions{}
	create := createOptions{}
	upCmd := &cobra.Command{
		Use:   "up [SERVICE...]",
		Short: "Create and start containers",
		PreRun: func(cmd *cobra.Command, args []string) {
			create.timeChanged = cmd.Flags().Changed("timeout")
		},
		PreRunE: Adapt(func(ctx context.Context, args []string) error {
			if up.exitCodeFrom != "" {
				up.cascadeStop = true
			}
			if up.wait != "" {
				up.Detach = true
			}
			if create.Build && create.noBuild {
				return fmt.Errorf("--build and --no-build are incompatible")
			}
			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")
			}
			if create.recreateDeps && create.noRecreate {
				return fmt.Errorf("--always-recreate-deps and --no-recreate are incompatible")
			}
			return nil
		}),
		RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
			ignore := project.Environment["COMPOSE_IGNORE_ORPHANS"]
			create.ignoreOrphans = strings.ToLower(ignore) == "true"
			if create.ignoreOrphans && create.removeOrphans {
				return fmt.Errorf("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined")
			}
			return runUp(ctx, backend, create, up, project, services)
		}),
		ValidArgsFunction: serviceCompletion(p),
	}

Review comment (suggestion):
I'm just wondering if the error msg when combining `Detach` with `attachDependencies`, `cascadeStop`, or `attach`  would be changed in some way because the user can get confused because `Detach` was set to true as a side effect.

Code after:
			return err
		}
		err = setServiceScale(project, name, uint64(replicas))
		if err != nil {
			return err
		}
	}

	return nil
}

func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
	up := upOptions{}
	create := createOptions{}
	upCmd := &cobra.Command{
		Use:   "up [SERVICE...]",
		Short: "Create and start containers",
		PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
			create.timeChanged = cmd.Flags().Changed("timeout")
			return validateFlags(&up, &create)
		}),
		RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
			ignore := project.Environment["COMPOSE_IGNORE_ORPHANS"]
			create.ignoreOrphans = strings.ToLower(ignore) == "true"
			if create.ignoreOrphans && create.removeOrphans {
				return fmt.Errorf("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined")
			}
			return runUp(ctx, backend, create, up, project, services)
		}),
		ValidArgsFunction: serviceCompletion(p),
	}
	flags := upCmd.Flags()
	flags.StringArrayVarP(&up.Environment, "environment", "e", []string{}, "Environment variables")
	flags.BoolVarP(&up.Detach, "detach", "d", false, "Detached mode: Run containers in the background")
	flags.BoolVar(&create.Build, "build", false, "Build images before starting containers.")
	flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's missing.")
	flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file.")
	flags.StringArrayVar(&up.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.")
	flags.BoolVar(&up.noColor, "no-color", false, "Produce monochrome output.")
	flags.BoolVar(&up.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.")
	flags.BoolVar(&create.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
	flags.BoolVar(&create.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
	flags.BoolVar(&up.noStart, "no-start", false, "Don't start the services after creating them.")
	flags.BoolVar(&up.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d")
	flags.StringVar(&up.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
	flags.IntVarP(&create.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.")
	flags.BoolVar(&up.noDeps, "no-deps", false, "Don't start linked services.")
	flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.")
	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.")