start.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "context"
  16. "github.com/docker/compose-cli/api/client"
  17. "github.com/docker/compose-cli/api/compose"
  18. "github.com/docker/compose-cli/api/progress"
  19. "github.com/spf13/cobra"
  20. )
  21. type startOptions struct {
  22. *projectOptions
  23. }
  24. func startCommand(p *projectOptions) *cobra.Command {
  25. opts := startOptions{
  26. projectOptions: p,
  27. }
  28. startCmd := &cobra.Command{
  29. Use: "start [SERVICE...]",
  30. Short: "Start services",
  31. RunE: func(cmd *cobra.Command, args []string) error {
  32. return runStart(cmd.Context(), opts, args)
  33. },
  34. }
  35. return startCmd
  36. }
  37. func runStart(ctx context.Context, opts startOptions, services []string) error {
  38. c, err := client.New(ctx)
  39. if err != nil {
  40. return err
  41. }
  42. project, err := opts.toProject(services)
  43. if err != nil {
  44. return err
  45. }
  46. _, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
  47. return "", c.ComposeService().Start(ctx, project, compose.StartOptions{})
  48. })
  49. return err
  50. }