123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- 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 main
- import (
- "os"
- dockercli "github.com/docker/cli/cli"
- "github.com/docker/cli/cli-plugins/manager"
- "github.com/docker/cli/cli-plugins/plugin"
- "github.com/docker/cli/cli/command"
- "github.com/docker/compose-switch/redirect"
- "github.com/spf13/cobra"
- commands "github.com/docker/compose/v2/cmd/compose"
- "github.com/docker/compose/v2/internal"
- "github.com/docker/compose/v2/pkg/api"
- "github.com/docker/compose/v2/pkg/compose"
- )
- func init() {
- commands.Warning = "The new 'docker compose' command is currently experimental. " +
- "To provide feedback or request new features please open issues at https://github.com/docker/compose"
- }
- func pluginMain() {
- plugin.Run(func(dockerCli command.Cli) *cobra.Command {
- lazyInit := api.NewServiceProxy()
- cmd := commands.RootCommand(lazyInit)
- originalPreRun := cmd.PersistentPreRunE
- cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
- if err := plugin.PersistentPreRunE(cmd, args); err != nil {
- return err
- }
- lazyInit.WithService(compose.NewComposeService(dockerCli.Client(), dockerCli.ConfigFile()))
- if originalPreRun != nil {
- return originalPreRun(cmd, args)
- }
- return nil
- }
- cmd.SetFlagErrorFunc(func(c *cobra.Command, err error) error {
- return dockercli.StatusError{
- StatusCode: compose.CommandSyntaxFailure.ExitCode,
- Status: err.Error(),
- }
- })
- return cmd
- },
- manager.Metadata{
- SchemaVersion: "0.1.0",
- Vendor: "Docker Inc.",
- Version: internal.Version,
- })
- }
- func main() {
- if commands.RunningAsStandalone() {
- os.Args = append([]string{"docker"}, redirect.Convert(os.Args[1:])...)
- }
- pluginMain()
- }
|