main.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/docker/cli/cli-plugins/manager"
  5. "github.com/docker/cli/cli-plugins/plugin"
  6. "github.com/docker/cli/cli/command"
  7. "github.com/docker/ecs-plugin/pkg/compose"
  8. "github.com/spf13/cobra"
  9. )
  10. const version = "0.0.1"
  11. func main() {
  12. plugin.Run(func(dockerCli command.Cli) *cobra.Command {
  13. cmd := NewRootCmd("ecs", dockerCli)
  14. return cmd
  15. }, manager.Metadata{
  16. SchemaVersion: "0.1.0",
  17. Vendor: "Docker Inc.",
  18. Version: version,
  19. Experimental: true,
  20. })
  21. }
  22. type clusterOptions struct {
  23. region string
  24. cluster string
  25. }
  26. // NewRootCmd returns the base root command.
  27. func NewRootCmd(name string, dockerCli command.Cli) *cobra.Command {
  28. var opts clusterOptions
  29. cmd := &cobra.Command{
  30. Short: "Docker ECS",
  31. Long: `run multi-container applications on Amazon ECS.`,
  32. Use: name,
  33. Annotations: map[string]string{"experimentalCLI": "true"},
  34. }
  35. cmd.AddCommand(
  36. VersionCommand(),
  37. ComposeCommand(&opts),
  38. )
  39. cmd.Flags().StringVarP(&opts.cluster, "cluster", "c", "default", "ECS cluster")
  40. cmd.Flags().StringVarP(&opts.region, "region", "r", "", "AWS region")
  41. return cmd
  42. }
  43. func VersionCommand() *cobra.Command {
  44. return &cobra.Command{
  45. Use: "version",
  46. Short: "Show version.",
  47. RunE: func(cmd *cobra.Command, args []string) error {
  48. fmt.Printf("Docker ECS plugin %s\n", version)
  49. return nil
  50. },
  51. }
  52. }
  53. func ComposeCommand(clusteropts *clusterOptions) *cobra.Command {
  54. cmd := &cobra.Command{
  55. Use: "compose",
  56. }
  57. opts := &compose.ProjectOptions{}
  58. opts.AddFlags(cmd.Flags())
  59. return cmd
  60. }