create.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package compose
  14. import (
  15. "github.com/spf13/cobra"
  16. )
  17. type createOptions struct {
  18. *composeOptions
  19. forceRecreate bool
  20. noRecreate bool
  21. }
  22. func createCommand(p *projectOptions) *cobra.Command {
  23. opts := createOptions{
  24. composeOptions: &composeOptions{},
  25. }
  26. cmd := &cobra.Command{
  27. Use: "create [SERVICE...]",
  28. Short: "Creates containers for a service.",
  29. RunE: func(cmd *cobra.Command, args []string) error {
  30. return runCreateStart(cmd.Context(), upOptions{
  31. composeOptions: &composeOptions{
  32. projectOptions: p,
  33. Build: opts.Build,
  34. },
  35. noStart: true,
  36. forceRecreate: opts.forceRecreate,
  37. noRecreate: opts.noRecreate,
  38. }, args)
  39. },
  40. }
  41. flags := cmd.Flags()
  42. flags.BoolVar(&opts.Build, "build", false, "Build images before starting containers.")
  43. flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
  44. flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
  45. return cmd
  46. }