compose.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright 2020 Docker, Inc.
  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. apicontext "github.com/docker/api/context"
  16. "github.com/docker/api/context/store"
  17. "github.com/docker/api/errdefs"
  18. "github.com/pkg/errors"
  19. "github.com/spf13/cobra"
  20. )
  21. // Command returns the compose command with its child commands
  22. func Command() *cobra.Command {
  23. command := &cobra.Command{
  24. Short: "Docker Compose",
  25. Use: "compose",
  26. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  27. currentContext := apicontext.CurrentContext(cmd.Context())
  28. s := store.ContextStore(cmd.Context())
  29. cc, err := s.Get(currentContext)
  30. if err != nil {
  31. return err
  32. }
  33. switch cc.Type() {
  34. case store.AciContextType:
  35. return nil
  36. case store.AwsContextType:
  37. return errors.New("use 'docker ecs compose' on context type " + cc.Type())
  38. default:
  39. return errors.Wrapf(errdefs.ErrNotImplemented, "compose command not supported on context type %q", cc.Type())
  40. }
  41. },
  42. }
  43. command.AddCommand(
  44. upCommand(),
  45. downCommand(),
  46. )
  47. return command
  48. }