(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 53 | } |
| 54 | |
| 55 | func createCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 56 | opts := createOptions{} |
| 57 | buildOpts := buildOptions{ |
| 58 | ProjectOptions: p, |
| 59 | } |
| 60 | cmd := &cobra.Command{ |
| 61 | Use: "create [OPTIONS] [SERVICE...]", |
| 62 | Short: "Creates containers for a service", |
| 63 | PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { |
| 64 | opts.pullChanged = cmd.Flags().Changed("pull") |
| 65 | if opts.Build && opts.noBuild { |
| 66 | return fmt.Errorf("--build and --no-build are incompatible") |
| 67 | } |
| 68 | if opts.forceRecreate && opts.noRecreate { |
| 69 | return fmt.Errorf("--force-recreate and --no-recreate are incompatible") |
| 70 | } |
| 71 | return nil |
| 72 | }), |
| 73 | RunE: p.WithServices(dockerCli, func(ctx context.Context, project *types.Project, services []string) error { |
| 74 | return runCreate(ctx, dockerCli, backendOptions, opts, buildOpts, project, services) |
| 75 | }), |
| 76 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 77 | } |
| 78 | flags := cmd.Flags() |
| 79 | flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers") |
| 80 | flags.BoolVar(&opts.noBuild, "no-build", false, "Don't build an image, even if it's policy") |
| 81 | flags.StringVar(&opts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never"|"build")`) |
| 82 | flags.BoolVar(&opts.quietPull, "quiet-pull", false, "Pull without printing progress information") |
| 83 | flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed") |
| 84 | flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.") |
| 85 | flags.BoolVar(&opts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") |
| 86 | flags.StringArrayVar(&opts.scale, "scale", []string{}, "Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.") |
| 87 | flags.BoolVarP(&opts.AssumeYes, "yes", "y", false, `Assume "yes" as answer to all prompts and run non-interactively`) |
| 88 | flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { |
| 89 | // assumeYes was introduced by mistake as `--y` |
| 90 | if name == "y" { |
| 91 | logrus.Warn("--y is deprecated, please use --yes instead") |
| 92 | name = "yes" |
| 93 | } |
| 94 | return pflag.NormalizedName(name) |
| 95 | }) |
| 96 | return cmd |
| 97 | } |
| 98 | |
| 99 | func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, createOpts createOptions, buildOpts buildOptions, project *types.Project, services []string) error { |
| 100 | if err := createOpts.Apply(project); err != nil { |
no test coverage detected