88 "strings"
99
1010 "github.com/compose-spec/compose-go/cli"
11- "github.com/compose-spec/compose-go/types"
1211 "github.com/docker/cli/cli/command"
1312 amazon "github.com/docker/ecs-plugin/pkg/amazon/backend"
1413 "github.com/docker/ecs-plugin/pkg/docker"
@@ -43,15 +42,11 @@ func (o upOptions) LoadBalancerArn() *string {
4342 return & o .loadBalancerArn
4443}
4544
46- func ConvertCommand (dockerCli command.Cli , projectOpts * cli.ProjectOptions ) * cobra.Command {
45+ func ConvertCommand (dockerCli command.Cli , options * cli.ProjectOptions ) * cobra.Command {
4746 cmd := & cobra.Command {
4847 Use : "convert" ,
49- RunE : WithProject (projectOpts , func (project * types.Project , args []string ) error {
50- clusteropts , err := docker .GetAwsContext (dockerCli )
51- if err != nil {
52- return err
53- }
54- backend , err := amazon .NewBackend (clusteropts .Profile , clusteropts .Cluster , clusteropts .Region )
48+ RunE : docker .WithAwsContext (dockerCli , func (ctx docker.AwsContext , backend * amazon.Backend , args []string ) error {
49+ project , err := cli .ProjectFromOptions (options )
5550 if err != nil {
5651 return err
5752 }
@@ -72,36 +67,24 @@ func ConvertCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cob
7267 return cmd
7368}
7469
75- func UpCommand (dockerCli command.Cli , projectOpts * cli.ProjectOptions ) * cobra.Command {
70+ func UpCommand (dockerCli command.Cli , options * cli.ProjectOptions ) * cobra.Command {
7671 opts := upOptions {}
7772 cmd := & cobra.Command {
7873 Use : "up" ,
79- RunE : docker .WithAwsContext (dockerCli , func (clusteropts docker.AwsContext , args []string ) error {
80- backend , err := amazon .NewBackend (clusteropts .Profile , clusteropts .Cluster , clusteropts .Region )
81- if err != nil {
82- return err
83- }
84- return backend .Up (context .Background (), * projectOpts )
74+ RunE : docker .WithAwsContext (dockerCli , func (clusteropts docker.AwsContext , backend * amazon.Backend , args []string ) error {
75+ return backend .Up (context .Background (), * options )
8576 }),
8677 }
8778 cmd .Flags ().StringVar (& opts .loadBalancerArn , "load-balancer" , "" , "" )
8879 return cmd
8980}
9081
91- func PsCommand (dockerCli command.Cli , projectOpts * cli.ProjectOptions ) * cobra.Command {
82+ func PsCommand (dockerCli command.Cli , options * cli.ProjectOptions ) * cobra.Command {
9283 opts := upOptions {}
9384 cmd := & cobra.Command {
9485 Use : "ps" ,
95- RunE : WithProject (projectOpts , func (project * types.Project , args []string ) error {
96- clusteropts , err := docker .GetAwsContext (dockerCli )
97- if err != nil {
98- return err
99- }
100- backend , err := amazon .NewBackend (clusteropts .Profile , clusteropts .Cluster , clusteropts .Region )
101- if err != nil {
102- return err
103- }
104- status , err := backend .Ps (context .Background (), project )
86+ RunE : docker .WithAwsContext (dockerCli , func (ctx docker.AwsContext , backend * amazon.Backend , args []string ) error {
87+ status , err := backend .Ps (context .Background (), * options )
10588 if err != nil {
10689 return err
10790 }
@@ -125,11 +108,7 @@ func DownCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.
125108 opts := downOptions {}
126109 cmd := & cobra.Command {
127110 Use : "down" ,
128- RunE : docker .WithAwsContext (dockerCli , func (clusteropts docker.AwsContext , args []string ) error {
129- backend , err := amazon .NewBackend (clusteropts .Profile , clusteropts .Cluster , clusteropts .Region )
130- if err != nil {
131- return err
132- }
111+ RunE : docker .WithAwsContext (dockerCli , func (ctx docker.AwsContext , backend * amazon.Backend , args []string ) error {
133112 return backend .Down (context .Background (), * projectOpts )
134113 }),
135114 }
@@ -140,23 +119,8 @@ func DownCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.
140119func LogsCommand (dockerCli command.Cli , projectOpts * cli.ProjectOptions ) * cobra.Command {
141120 cmd := & cobra.Command {
142121 Use : "logs [PROJECT NAME]" ,
143- RunE : docker .WithAwsContext (dockerCli , func (clusteropts docker.AwsContext , args []string ) error {
144- backend , err := amazon .NewBackend (clusteropts .Profile , clusteropts .Cluster , clusteropts .Region )
145- if err != nil {
146- return err
147- }
148- var name string
149-
150- if len (args ) == 0 {
151- project , err := cli .ProjectFromOptions (projectOpts )
152- if err != nil {
153- return err
154- }
155- name = project .Name
156- } else {
157- name = args [0 ]
158- }
159- return backend .Logs (context .Background (), name )
122+ RunE : docker .WithAwsContext (dockerCli , func (clusteropts docker.AwsContext , backend * amazon.Backend , args []string ) error {
123+ return backend .Logs (context .Background (), * projectOpts )
160124 }),
161125 }
162126 return cmd
0 commit comments