2021-01-26 18:42:49 -03: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"
|
2021-02-12 10:19:26 +01:00
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
"github.com/docker/cli/cli/command"
|
2021-08-31 18:53:24 +02:00
|
|
|
"github.com/docker/compose/v2/pkg/api"
|
2021-02-09 16:51:48 +01:00
|
|
|
"github.com/spf13/cobra"
|
2021-01-26 18:42:49 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
type startOptions struct {
|
2022-12-19 16:38:36 +00:00
|
|
|
*ProjectOptions
|
2021-01-26 18:42:49 -03:00
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func startCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
|
2021-01-26 18:42:49 -03:00
|
|
|
opts := startOptions{
|
2022-12-19 16:38:36 +00:00
|
|
|
ProjectOptions: p,
|
2021-01-26 18:42:49 -03:00
|
|
|
}
|
|
|
|
startCmd := &cobra.Command{
|
|
|
|
Use: "start [SERVICE...]",
|
|
|
|
Short: "Start 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 runStart(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-01-26 18:42:49 -03:00
|
|
|
}
|
|
|
|
return startCmd
|
|
|
|
}
|
|
|
|
|
2023-08-30 10:15:35 +02:00
|
|
|
func runStart(ctx context.Context, dockerCli command.Cli, backend api.Service, opts startOptions, services []string) error {
|
2024-02-05 17:38:15 -05:00
|
|
|
project, name, err := opts.projectOrName(ctx, dockerCli, services...)
|
2021-01-29 12:23:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-11 10:58:20 +02:00
|
|
|
return backend.Start(ctx, name, api.StartOptions{
|
2022-02-05 10:27:52 +03:30
|
|
|
AttachTo: services,
|
2022-04-11 10:58:20 +02:00
|
|
|
Project: project,
|
2022-09-06 20:31:42 +02:00
|
|
|
Services: services,
|
2022-02-05 10:27:52 +03:30
|
|
|
})
|
2021-01-26 18:42:49 -03:00
|
|
|
}
|