(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 111 | } |
| 112 | |
| 113 | func upCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 114 | up := upOptions{} |
| 115 | create := createOptions{} |
| 116 | build := buildOptions{ProjectOptions: p} |
| 117 | upCmd := &cobra.Command{ |
| 118 | Use: "up [OPTIONS] [SERVICE...]", |
| 119 | Short: "Create and start containers", |
| 120 | PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { |
| 121 | create.pullChanged = cmd.Flags().Changed("pull") |
| 122 | create.timeChanged = cmd.Flags().Changed("timeout") |
| 123 | up.navigationMenuChanged = cmd.Flags().Changed("menu") |
| 124 | if !cmd.Flags().Changed("remove-orphans") { |
| 125 | create.removeOrphans = utils.StringToBool(os.Getenv(ComposeRemoveOrphans)) |
| 126 | } |
| 127 | return validateFlags(&up, &create) |
| 128 | }), |
| 129 | RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error { |
| 130 | create.ignoreOrphans = utils.StringToBool(project.Environment[ComposeIgnoreOrphans]) |
| 131 | if create.ignoreOrphans && create.removeOrphans { |
| 132 | return fmt.Errorf("cannot combine %s and --remove-orphans", ComposeIgnoreOrphans) |
| 133 | } |
| 134 | if len(up.attach) != 0 && up.attachDependencies { |
| 135 | return errors.New("cannot combine --attach and --attach-dependencies") |
| 136 | } |
| 137 | |
| 138 | up.validateNavigationMenu(dockerCli) |
| 139 | |
| 140 | if !p.All && len(project.Services) == 0 { |
| 141 | return fmt.Errorf("no service selected") |
| 142 | } |
| 143 | |
| 144 | return runUp(ctx, dockerCli, backendOptions, create, up, build, project, services) |
| 145 | }), |
| 146 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 147 | } |
| 148 | flags := upCmd.Flags() |
| 149 | flags.BoolVarP(&up.Detach, "detach", "d", false, "Detached mode: Run containers in the background") |
| 150 | flags.BoolVar(&create.Build, "build", false, "Build images before starting containers") |
| 151 | flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's policy") |
| 152 | flags.StringVar(&create.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`) |
| 153 | flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") |
| 154 | flags.StringArrayVar(&create.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.") |
| 155 | flags.BoolVar(&up.noColor, "no-color", false, "Produce monochrome output") |
| 156 | flags.BoolVar(&up.noPrefix, "no-log-prefix", false, "Don't print prefix in logs") |
| 157 | flags.BoolVar(&create.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed") |
| 158 | flags.BoolVar(&create.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.") |
| 159 | flags.BoolVar(&up.noStart, "no-start", false, "Don't start the services after creating them") |
| 160 | flags.BoolVar(&up.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d") |
| 161 | flags.BoolVar(&up.cascadeFail, "abort-on-container-failure", false, "Stops all containers if any container exited with failure. Incompatible with -d") |
| 162 | flags.StringVar(&up.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit") |
| 163 | flags.IntVarP(&create.timeout, "timeout", "t", 0, "Use this timeout in seconds for container shutdown when attached or when containers are already running") |
| 164 | flags.BoolVar(&up.timestamp, "timestamps", false, "Show timestamps") |
| 165 | flags.BoolVar(&up.noDeps, "no-deps", false, "Don't start linked services") |
| 166 | flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.") |
| 167 | flags.BoolVarP(&create.noInherit, "renew-anon-volumes", "V", false, "Recreate anonymous volumes instead of retrieving data from the previous containers") |
| 168 | flags.BoolVar(&create.quietPull, "quiet-pull", false, "Pull without printing progress information") |
| 169 | flags.BoolVar(&build.quiet, "quiet-build", false, "Suppress the build output") |
| 170 | flags.StringArrayVar(&up.attach, "attach", []string{}, "Restrict attaching to the specified services. Incompatible with --attach-dependencies.") |
no test coverage detected