2021-02-22 10:25:40 +01:00
|
|
|
/*
|
|
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package compose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2021-08-31 18:53:24 +02:00
|
|
|
"github.com/docker/compose/v2/pkg/api"
|
2021-02-22 10:25:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type pauseOptions struct {
|
|
|
|
*projectOptions
|
|
|
|
}
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
func pauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
|
2021-02-22 10:25:40 +01:00
|
|
|
opts := pauseOptions{
|
|
|
|
projectOptions: p,
|
|
|
|
}
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "pause [SERVICE...]",
|
2021-10-04 06:43:30 +02:00
|
|
|
Short: "Pause services",
|
2021-04-15 12:43:18 +02:00
|
|
|
RunE: Adapt(func(ctx context.Context, args []string) error {
|
|
|
|
return runPause(ctx, backend, opts, args)
|
|
|
|
}),
|
2022-09-26 19:21:45 +02:00
|
|
|
ValidArgsFunction: completeServiceNames(p),
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
func runPause(ctx context.Context, backend api.Service, opts pauseOptions, services []string) error {
|
2022-11-28 22:07:36 +01:00
|
|
|
project, name, err := opts.projectOrName(services...)
|
2021-02-22 10:25:40 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-11 10:58:20 +02:00
|
|
|
return backend.Pause(ctx, name, api.PauseOptions{
|
2021-06-03 13:57:56 +02:00
|
|
|
Services: services,
|
2022-04-11 10:58:20 +02:00
|
|
|
Project: project,
|
2021-02-22 10:25:40 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type unpauseOptions struct {
|
|
|
|
*projectOptions
|
|
|
|
}
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
func unpauseCommand(p *projectOptions, backend api.Service) *cobra.Command {
|
2021-02-22 10:25:40 +01:00
|
|
|
opts := unpauseOptions{
|
|
|
|
projectOptions: p,
|
|
|
|
}
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unpause [SERVICE...]",
|
2021-10-04 06:43:30 +02:00
|
|
|
Short: "Unpause services",
|
2021-04-15 12:43:18 +02:00
|
|
|
RunE: Adapt(func(ctx context.Context, args []string) error {
|
|
|
|
return runUnPause(ctx, backend, opts, args)
|
|
|
|
}),
|
2022-09-26 19:21:45 +02:00
|
|
|
ValidArgsFunction: completeServiceNames(p),
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
func runUnPause(ctx context.Context, backend api.Service, opts unpauseOptions, services []string) error {
|
2022-11-28 22:07:36 +01:00
|
|
|
project, name, err := opts.projectOrName(services...)
|
2021-02-22 10:25:40 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-11 10:58:20 +02:00
|
|
|
return backend.UnPause(ctx, name, api.PauseOptions{
|
2021-06-03 13:57:56 +02:00
|
|
|
Services: services,
|
2022-04-11 10:58:20 +02:00
|
|
|
Project: project,
|
2021-02-22 10:25:40 +01:00
|
|
|
})
|
|
|
|
}
|