main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. commands "github.com/docker/ecs-plugin/cmd/commands"
  8. "github.com/docker/ecs-plugin/pkg/docker"
  9. "github.com/spf13/cobra"
  10. )
  11. const version = "0.0.1"
  12. func main() {
  13. plugin.Run(func(dockerCli command.Cli) *cobra.Command {
  14. cmd := NewRootCmd("ecs", dockerCli)
  15. return cmd
  16. }, manager.Metadata{
  17. SchemaVersion: "0.1.0",
  18. Vendor: "Docker Inc.",
  19. Version: version,
  20. Experimental: true,
  21. })
  22. }
  23. // NewRootCmd returns the base root command.
  24. func NewRootCmd(name string, dockerCli command.Cli) *cobra.Command {
  25. var opts *docker.AwsContext
  26. cmd := &cobra.Command{
  27. Short: "Docker ECS",
  28. Long: `run multi-container applications on Amazon ECS.`,
  29. Use: name,
  30. Annotations: map[string]string{"experimentalCLI": "true"},
  31. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  32. err := plugin.PersistentPreRunE(cmd, args)
  33. if err != nil {
  34. return err
  35. }
  36. contextName := dockerCli.CurrentContext()
  37. opts, err = docker.CheckAwsContextExists(contextName)
  38. return err
  39. },
  40. }
  41. cmd.AddCommand(
  42. VersionCommand(),
  43. commands.ComposeCommand(opts),
  44. commands.SecretCommand(opts),
  45. commands.SetupCommand(),
  46. )
  47. return cmd
  48. }
  49. func VersionCommand() *cobra.Command {
  50. return &cobra.Command{
  51. Use: "version",
  52. Short: "Show version.",
  53. RunE: func(cmd *cobra.Command, args []string) error {
  54. fmt.Printf("Docker ECS plugin %s\n", version)
  55. return nil
  56. },
  57. }
  58. }