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"
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
"github.com/docker/cli/cli/command"
|
2021-02-22 10:25:40 +01:00
|
|
|
"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 {
|
2022-12-19 16:38:36 +00:00
|
|
|
*ProjectOptions
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func pauseCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
|
2021-02-22 10:25:40 +01:00
|
|
|
opts := pauseOptions{
|
2022-12-19 16:38:36 +00:00
|
|
|
ProjectOptions: p,
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
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 {
|
2023-08-30 10:15:35 +02:00
|
|
|
return runPause(ctx, dockerCli, backend, opts, args)
|
2021-04-15 12:43:18 +02:00
|
|
|
}),
|
2023-08-30 10:15:35 +02:00
|
|
|
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func runPause(ctx context.Context, dockerCli command.Cli, backend api.Service, opts pauseOptions, services []string) error {
|
2024-02-05 17:38:15 -05:00
|
|
|
project, name, err := opts.projectOrName(ctx, dockerCli, 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 {
|
2022-12-19 16:38:36 +00:00
|
|
|
*ProjectOptions
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func unpauseCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
|
2021-02-22 10:25:40 +01:00
|
|
|
opts := unpauseOptions{
|
2022-12-19 16:38:36 +00:00
|
|
|
ProjectOptions: p,
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
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 {
|
2023-08-30 10:15:35 +02:00
|
|
|
return runUnPause(ctx, dockerCli, backend, opts, args)
|
2021-04-15 12:43:18 +02:00
|
|
|
}),
|
2023-08-30 10:15:35 +02:00
|
|
|
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
2021-02-22 10:25:40 +01:00
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func runUnPause(ctx context.Context, dockerCli command.Cli, backend api.Service, opts unpauseOptions, services []string) error {
|
2024-02-05 17:38:15 -05:00
|
|
|
project, name, err := opts.projectOrName(ctx, dockerCli, 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
|
|
|
})
|
|
|
|
}
|