pause.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/spf13/cobra"
  17. "github.com/docker/compose/v2/pkg/api"
  18. )
  19. type pauseOptions struct {
  20. *projectOptions
  21. }
  22. func pauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
  23. opts := pauseOptions{
  24. projectOptions: p,
  25. }
  26. cmd := &cobra.Command{
  27. Use: "pause [SERVICE...]",
  28. Short: "Pause services",
  29. RunE: Adapt(func(ctx context.Context, args []string) error {
  30. return runPause(ctx, backend, opts, args)
  31. }),
  32. ValidArgsFunction: serviceCompletion(p),
  33. }
  34. return cmd
  35. }
  36. func runPause(ctx context.Context, backend api.Service, opts pauseOptions, services []string) error {
  37. project, err := opts.toProjectName()
  38. if err != nil {
  39. return err
  40. }
  41. return backend.Pause(ctx, project, api.PauseOptions{
  42. Services: services,
  43. })
  44. }
  45. type unpauseOptions struct {
  46. *projectOptions
  47. }
  48. func unpauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
  49. opts := unpauseOptions{
  50. projectOptions: p,
  51. }
  52. cmd := &cobra.Command{
  53. Use: "unpause [SERVICE...]",
  54. Short: "Unpause services",
  55. RunE: Adapt(func(ctx context.Context, args []string) error {
  56. return runUnPause(ctx, backend, opts, args)
  57. }),
  58. ValidArgsFunction: serviceCompletion(p),
  59. }
  60. return cmd
  61. }
  62. func runUnPause(ctx context.Context, backend api.Service, opts unpauseOptions, services []string) error {
  63. project, err := opts.toProjectName()
  64. if err != nil {
  65. return err
  66. }
  67. return backend.UnPause(ctx, project, api.PauseOptions{
  68. Services: services,
  69. })
  70. }