setup.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. package commands
  2. import (
  3. "github.com/docker/cli/cli-plugins/plugin"
  4. contextStore "github.com/docker/ecs-plugin/pkg/docker"
  5. "github.com/spf13/cobra"
  6. )
  7. func SetupCommand() *cobra.Command {
  8. var opts contextStore.AwsContext
  9. var name string
  10. cmd := &cobra.Command{
  11. Use: "setup",
  12. Short: "",
  13. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  14. //Override the root command PersistentPreRun
  15. //We just need to initialize the top parent command
  16. return plugin.PersistentPreRunE(cmd, args)
  17. },
  18. RunE: func(cmd *cobra.Command, args []string) error {
  19. return contextStore.NewContext(name, &opts)
  20. },
  21. }
  22. cmd.Flags().StringVarP(&name, "name", "n", "aws", "Context Name")
  23. cmd.Flags().StringVarP(&opts.Profile, "profile", "p", "", "AWS Profile")
  24. cmd.Flags().StringVarP(&opts.Cluster, "cluster", "c", "", "ECS cluster")
  25. cmd.Flags().StringVarP(&opts.Region, "region", "r", "", "AWS region")
  26. cmd.MarkFlagRequired("profile")
  27. cmd.MarkFlagRequired("cluster")
  28. cmd.MarkFlagRequired("region")
  29. return cmd
  30. }