Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 25b3359

Browse files
committed
Store context type in the context for reusing
Signed-off-by: Ulysses Souza <[email protected]>
1 parent dc7422e commit 25b3359

File tree

11 files changed

+55
-65
lines changed

11 files changed

+55
-65
lines changed

aci/compose.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func (cs *aciComposeService) Copy(ctx context.Context, project *types.Project, o
8686
}
8787

8888
func (cs *aciComposeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
89-
if err := checkUnsupportedUpOptions(options); err != nil {
89+
if err := checkUnsupportedUpOptions(ctx, options); err != nil {
9090
return err
9191
}
9292
return progress.Run(ctx, func(ctx context.Context) error {
9393
return cs.up(ctx, project)
9494
})
9595
}
9696

97-
func checkUnsupportedUpOptions(o api.UpOptions) error {
97+
func checkUnsupportedUpOptions(ctx context.Context, o api.UpOptions) error {
9898
var errs error
9999
checks := []struct {
100100
toCheck, expected interface{}
@@ -111,7 +111,7 @@ func checkUnsupportedUpOptions(o api.UpOptions) error {
111111
{o.Create.Timeout, nil, "timeout"},
112112
}
113113
for _, c := range checks {
114-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "up", c.option)
114+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "up", c.option)
115115
}
116116
return errs
117117
}
@@ -155,7 +155,7 @@ func (cs aciComposeService) warnKeepVolumeOnDown(ctx context.Context, projectNam
155155
}
156156

157157
func (cs *aciComposeService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
158-
if err := checkUnsupportedDownOptions(options); err != nil {
158+
if err := checkUnsupportedDownOptions(ctx, options); err != nil {
159159
return err
160160
}
161161
return progress.Run(ctx, func(ctx context.Context) error {
@@ -177,15 +177,15 @@ func (cs *aciComposeService) Down(ctx context.Context, projectName string, optio
177177
})
178178
}
179179

180-
func checkUnsupportedDownOptions(o api.DownOptions) error {
180+
func checkUnsupportedDownOptions(ctx context.Context, o api.DownOptions) error {
181181
var errs error
182-
errs = utils.CheckUnsupported(errs, o.Volumes, false, "down", "volumes")
183-
errs = utils.CheckUnsupported(errs, o.Images, "", "down", "images")
182+
errs = utils.CheckUnsupported(ctx, errs, o.Volumes, false, "down", "volumes")
183+
errs = utils.CheckUnsupported(ctx, errs, o.Images, "", "down", "images")
184184
return errs
185185
}
186186

187187
func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
188-
if err := checkUnsupportedPsOptions(options); err != nil {
188+
if err := checkUnsupportedPsOptions(ctx, options); err != nil {
189189
return nil, err
190190
}
191191
groupsClient, err := login.NewContainerGroupsClient(cs.ctx.SubscriptionID)
@@ -230,12 +230,12 @@ func (cs *aciComposeService) Ps(ctx context.Context, projectName string, options
230230
return res, nil
231231
}
232232

233-
func checkUnsupportedPsOptions(o api.PsOptions) error {
234-
return utils.CheckUnsupported(nil, o.All, false, "ps", "all")
233+
func checkUnsupportedPsOptions(ctx context.Context, o api.PsOptions) error {
234+
return utils.CheckUnsupported(ctx,nil, o.All, false, "ps", "all")
235235
}
236236

237237
func (cs *aciComposeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
238-
if err := checkUnsupportedListOptions(opts); err != nil {
238+
if err := checkUnsupportedListOptions(ctx, opts); err != nil {
239239
return nil, err
240240
}
241241
containerGroups, err := getACIContainerGroups(ctx, cs.ctx.SubscriptionID, cs.ctx.ResourceGroup)
@@ -265,8 +265,8 @@ func (cs *aciComposeService) List(ctx context.Context, opts api.ListOptions) ([]
265265
return stacks, nil
266266
}
267267

268-
func checkUnsupportedListOptions(o api.ListOptions) error {
269-
return utils.CheckUnsupported(nil, o.All, false, "ls", "all")
268+
func checkUnsupportedListOptions(ctx context.Context, o api.ListOptions) error {
269+
return utils.CheckUnsupported(ctx, nil, o.All, false, "ls", "all")
270270
}
271271

272272
func (cs *aciComposeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {

api/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"github.com/docker/compose-cli/api/context/store"
2828
)
2929

30+
const ContextTypeKey = "context_type"
31+
3032
var configDir string
3133

3234
// WithDir sets the config directory path in the context

cli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func main() {
214214
if cc != nil {
215215
ctype = cc.Type()
216216
}
217+
ctx = context.WithValue(ctx, config.ContextTypeKey, ctype)
217218

218219
service, err := getBackend(ctype, configDir, opts)
219220
if err != nil {

ecs/cloudformation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
)
4848

4949
func (b *ecsAPIService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) {
50-
if err := checkUnsupportedConvertOptions(options); err != nil {
50+
if err := checkUnsupportedConvertOptions(ctx, options); err != nil {
5151
return nil, err
5252
}
5353
err := b.resolveServiceImagesDigests(ctx, project)
@@ -101,8 +101,8 @@ func (b *ecsAPIService) Convert(ctx context.Context, project *types.Project, opt
101101
return bytes, err
102102
}
103103

104-
func checkUnsupportedConvertOptions(o api.ConvertOptions) error {
105-
return utils.CheckUnsupported(nil, o.Output, "", "convert", "output")
104+
func checkUnsupportedConvertOptions(ctx context.Context, o api.ConvertOptions) error {
105+
return utils.CheckUnsupported(ctx, nil, o.Output, "", "convert", "output")
106106
}
107107

108108
func (b *ecsAPIService) resolveServiceImagesDigests(ctx context.Context, project *types.Project) error {

ecs/down.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func (b *ecsAPIService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
28-
if err := checkUnsupportedDownOptions(options); err != nil {
28+
if err := checkUnsupportedDownOptions(ctx, options); err != nil {
2929
return err
3030
}
3131
return progress.Run(ctx, func(ctx context.Context) error {
@@ -87,7 +87,7 @@ func doDelete(ctx context.Context, delete func(ctx context.Context, arn string)
8787
}
8888
}
8989

90-
func checkUnsupportedDownOptions(o api.DownOptions) error {
90+
func checkUnsupportedDownOptions(ctx context.Context, o api.DownOptions) error {
9191
var errs error
9292
checks := []struct {
9393
toCheck, expected interface{}
@@ -99,7 +99,7 @@ func checkUnsupportedDownOptions(o api.DownOptions) error {
9999
{o.Timeout, nil, "timeout"},
100100
}
101101
for _, c := range checks {
102-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "down", c.option)
102+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "down", c.option)
103103
}
104104

105105
return errs

ecs/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func (b *ecsAPIService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
28-
if err := checkUnsupportedListOptions(opts); err != nil {
28+
if err := checkUnsupportedListOptions(ctx, opts); err != nil {
2929
return nil, err
3030
}
3131
stacks, err := b.aws.ListStacks(ctx)
@@ -45,8 +45,8 @@ func (b *ecsAPIService) List(ctx context.Context, opts api.ListOptions) ([]api.S
4545

4646
}
4747

48-
func checkUnsupportedListOptions(o api.ListOptions) error {
49-
return utils.CheckUnsupported(nil, o.All, false, "ls", "all")
48+
func checkUnsupportedListOptions(ctx context.Context, o api.ListOptions) error {
49+
return utils.CheckUnsupported(ctx, nil, o.All, false, "ls", "all")
5050
}
5151

5252
func (b *ecsAPIService) checkStackState(ctx context.Context, name string) error {

ecs/logs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
func (b *ecsAPIService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
28-
if err := checkUnsupportedLogOptions(options); err != nil {
28+
if err := checkUnsupportedLogOptions(ctx, options); err != nil {
2929
return err
3030
}
3131
if len(options.Services) > 0 {
@@ -35,7 +35,7 @@ func (b *ecsAPIService) Logs(ctx context.Context, projectName string, consumer a
3535
return err
3636
}
3737

38-
func checkUnsupportedLogOptions(o api.LogOptions) error {
38+
func checkUnsupportedLogOptions(ctx context.Context, o api.LogOptions) error {
3939
var errs error
4040
checks := []struct {
4141
toCheck, expected interface{}
@@ -47,7 +47,7 @@ func checkUnsupportedLogOptions(o api.LogOptions) error {
4747
{o.Until, "", "until"},
4848
}
4949
for _, c := range checks {
50-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "logs", c.option)
50+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "logs", c.option)
5151
}
5252
return errs
5353
}

ecs/ps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) {
27-
if err := checkUnsupportedPsOptions(options); err != nil {
27+
if err := checkUnsupportedPsOptions(ctx, options); err != nil {
2828
return nil, err
2929
}
3030

@@ -62,6 +62,6 @@ func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options api.
6262
return summary, nil
6363
}
6464

65-
func checkUnsupportedPsOptions(o api.PsOptions) error {
66-
return utils.CheckUnsupported(nil, o.All, false, "ps", "all")
65+
func checkUnsupportedPsOptions(ctx context.Context, o api.PsOptions) error {
66+
return utils.CheckUnsupported(ctx, nil, o.All, false, "ps", "all")
6767
}

ecs/up.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
34-
if err := checkUnsupportedUpOptions(options); err != nil {
34+
if err := checkUnsupportedUpOptions(ctx, options); err != nil {
3535
return err
3636
}
3737
return progress.Run(ctx, func(ctx context.Context) error {
@@ -99,7 +99,7 @@ func (b *ecsAPIService) up(ctx context.Context, project *types.Project, options
9999
return err
100100
}
101101

102-
func checkUnsupportedUpOptions(o api.UpOptions) error {
102+
func checkUnsupportedUpOptions(ctx context.Context, o api.UpOptions) error {
103103
var errs error
104104
checks := []struct {
105105
toCheck, expected interface{}
@@ -115,7 +115,7 @@ func checkUnsupportedUpOptions(o api.UpOptions) error {
115115
{o.Create.Timeout, nil, "timeout"},
116116
}
117117
for _, c := range checks {
118-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "up", c.option)
118+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "up", c.option)
119119
}
120120
return errs
121121
}

kube/compose.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ func NewComposeService() (api.Service, error) {
7171

7272
// Up executes the equivalent to a `compose up`
7373
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
74-
if err := checkUnsupportedUpOptions(options); err != nil {
74+
if err := checkUnsupportedUpOptions(ctx, options); err != nil {
7575
return err
7676
}
7777
return progress.Run(ctx, func(ctx context.Context) error {
7878
return s.up(ctx, project)
7979
})
8080
}
8181

82-
func checkUnsupportedUpOptions(o api.UpOptions) error {
82+
func checkUnsupportedUpOptions(ctx context.Context, o api.UpOptions) error {
8383
var errs error
8484
checks := []struct {
8585
toCheck, expected interface{}
@@ -95,7 +95,7 @@ func checkUnsupportedUpOptions(o api.UpOptions) error {
9595
{o.Create.Timeout, nil, "timeout"},
9696
}
9797
for _, c := range checks {
98-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "up", c.option)
98+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "up", c.option)
9999
}
100100
return errs
101101
}
@@ -155,15 +155,15 @@ func (s *composeService) up(ctx context.Context, project *types.Project) error {
155155

156156
// Down executes the equivalent to a `compose down`
157157
func (s *composeService) Down(ctx context.Context, projectName string, options api.DownOptions) error {
158-
if err := checkUnsupportedDownOptions(options); err != nil {
158+
if err := checkUnsupportedDownOptions(ctx, options); err != nil {
159159
return err
160160
}
161161
return progress.Run(ctx, func(ctx context.Context) error {
162162
return s.down(ctx, projectName, options)
163163
})
164164
}
165165

166-
func checkUnsupportedDownOptions(o api.DownOptions) error {
166+
func checkUnsupportedDownOptions(ctx context.Context, o api.DownOptions) error {
167167
var errs error
168168
checks := []struct {
169169
toCheck, expected interface{}
@@ -174,7 +174,7 @@ func checkUnsupportedDownOptions(o api.DownOptions) error {
174174
{o.RemoveOrphans, false, "remove-orphans"},
175175
}
176176
for _, c := range checks {
177-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "down", c.option)
177+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "down", c.option)
178178
}
179179
return errs
180180
}
@@ -229,14 +229,14 @@ func (s *composeService) down(ctx context.Context, projectName string, options a
229229

230230
// List executes the equivalent to a `docker stack ls`
231231
func (s *composeService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) {
232-
if err := checkUnsupportedListOptions(opts); err != nil {
232+
if err := checkUnsupportedListOptions(ctx, opts); err != nil {
233233
return nil, err
234234
}
235235
return s.sdk.ListReleases()
236236
}
237237

238-
func checkUnsupportedListOptions(o api.ListOptions) error {
239-
return utils.CheckUnsupported(nil, o.All, false, "ls", "all")
238+
func checkUnsupportedListOptions(ctx context.Context, o api.ListOptions) error {
239+
return utils.CheckUnsupported(ctx, nil, o.All, false, "ls", "all")
240240
}
241241

242242
// Build executes the equivalent to a `compose build`
@@ -281,7 +281,7 @@ func (s *composeService) Copy(ctx context.Context, project *types.Project, optio
281281

282282
// Logs executes the equivalent to a `compose logs`
283283
func (s *composeService) Logs(ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions) error {
284-
if err := checkUnsupportedLogOptions(options); err != nil {
284+
if err := checkUnsupportedLogOptions(ctx, options); err != nil {
285285
return err
286286
}
287287
if len(options.Services) > 0 {
@@ -290,7 +290,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
290290
return s.client.GetLogs(ctx, projectName, consumer, options.Follow)
291291
}
292292

293-
func checkUnsupportedLogOptions(o api.LogOptions) error {
293+
func checkUnsupportedLogOptions(ctx context.Context, o api.LogOptions) error {
294294
var errs error
295295
checks := []struct {
296296
toCheck, expected interface{}
@@ -301,7 +301,7 @@ func checkUnsupportedLogOptions(o api.LogOptions) error {
301301
{o.Until, "", "until"},
302302
}
303303
for _, c := range checks {
304-
errs = utils.CheckUnsupported(errs, c.toCheck, c.expected, "logs", c.option)
304+
errs = utils.CheckUnsupported(ctx, errs, c.toCheck, c.expected, "logs", c.option)
305305
}
306306
return errs
307307
}
@@ -348,17 +348,17 @@ func (s *composeService) Remove(ctx context.Context, project *types.Project, opt
348348

349349
// Exec executes a command in a running service container
350350
func (s *composeService) Exec(ctx context.Context, project *types.Project, opts api.RunOptions) (int, error) {
351-
if err := checkUnsupportedExecOptions(opts); err != nil {
351+
if err := checkUnsupportedExecOptions(ctx, opts); err != nil {
352352
return 0, err
353353
}
354354
return 0, s.client.Exec(ctx, project.Name, opts)
355355
}
356356

357-
func checkUnsupportedExecOptions(o api.RunOptions) error {
357+
func checkUnsupportedExecOptions(ctx context.Context, o api.RunOptions) error {
358358
var errs error
359-
errs = utils.CheckUnsupported(errs, o.Index, 0, "exec", "index")
360-
errs = utils.CheckUnsupported(errs, o.Privileged, false, "exec", "privileged")
361-
errs = utils.CheckUnsupported(errs, o.WorkingDir, "", "exec", "workdir")
359+
errs = utils.CheckUnsupported(ctx, errs, o.Index, 0, "exec", "index")
360+
errs = utils.CheckUnsupported(ctx, errs, o.Privileged, false, "exec", "privileged")
361+
errs = utils.CheckUnsupported(ctx, errs, o.WorkingDir, "", "exec", "workdir")
362362
return errs
363363
}
364364

0 commit comments

Comments
 (0)