alpha.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  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. "context"
  16. "github.com/docker/compose/v2/pkg/api"
  17. "github.com/spf13/cobra"
  18. )
  19. // alphaCommand groups all experimental subcommands
  20. func alphaCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
  21. cmd := &cobra.Command{
  22. Short: "Experimental commands",
  23. Use: "alpha [COMMAND]",
  24. Hidden: true,
  25. Annotations: map[string]string{
  26. "experimentalCLI": "true",
  27. },
  28. }
  29. cmd.AddCommand(
  30. watchCommand(p, backend),
  31. dryRunRedirectCommand(p),
  32. vizCommand(p),
  33. )
  34. return cmd
  35. }
  36. // Temporary alpha command as the dry-run will be implemented with a flag
  37. func dryRunRedirectCommand(p *ProjectOptions) *cobra.Command {
  38. cmd := &cobra.Command{
  39. Use: "dry-run -- [COMMAND...]",
  40. Short: "EXPERIMENTAL - Dry run command allow you to test a command without applying changes",
  41. PreRunE: Adapt(func(ctx context.Context, args []string) error {
  42. return nil
  43. }),
  44. RunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
  45. rootCmd := cmd.Root()
  46. rootCmd.SetArgs(append([]string{"compose", "--dry-run"}, args...))
  47. return rootCmd.Execute()
  48. }),
  49. ValidArgsFunction: completeServiceNames(p),
  50. }
  51. return cmd
  52. }