pause.go 2.0 KB

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