Skip to content

Commit f3e543f

Browse files
committed
apply config options for pseudo-subcommands
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 24ff098 commit f3e543f

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

cmd/compose/config.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/docker/compose/v2/pkg/compose"
3333
)
3434

35-
type convertOptions struct {
35+
type configOptions struct {
3636
*ProjectOptions
3737
Format string
3838
Output string
@@ -48,8 +48,17 @@ type convertOptions struct {
4848
noConsistency bool
4949
}
5050

51+
func (o *configOptions) ToProject(services []string) (*types.Project, error) {
52+
return o.ProjectOptions.ToProject(services,
53+
cli.WithInterpolation(!o.noInterpolate),
54+
cli.WithResolvedPaths(true),
55+
cli.WithNormalization(!o.noNormalize),
56+
cli.WithConsistency(!o.noConsistency),
57+
cli.WithDiscardEnvFile)
58+
}
59+
5160
func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cobra.Command {
52-
opts := convertOptions{
61+
opts := configOptions{
5362
ProjectOptions: p,
5463
}
5564
cmd := &cobra.Command{
@@ -108,14 +117,9 @@ func convertCommand(p *ProjectOptions, streams api.Streams, backend api.Service)
108117
return cmd
109118
}
110119

111-
func runConfig(ctx context.Context, streams api.Streams, backend api.Service, opts convertOptions, services []string) error {
120+
func runConfig(ctx context.Context, streams api.Streams, backend api.Service, opts configOptions, services []string) error {
112121
var content []byte
113-
project, err := opts.ToProject(services,
114-
cli.WithInterpolation(!opts.noInterpolate),
115-
cli.WithResolvedPaths(true),
116-
cli.WithNormalization(!opts.noNormalize),
117-
cli.WithConsistency(!opts.noConsistency),
118-
cli.WithDiscardEnvFile)
122+
project, err := opts.ToProject(services)
119123
if err != nil {
120124
return err
121125
}
@@ -144,7 +148,7 @@ func runConfig(ctx context.Context, streams api.Streams, backend api.Service, op
144148
return err
145149
}
146150

147-
func runServices(streams api.Streams, opts convertOptions) error {
151+
func runServices(streams api.Streams, opts configOptions) error {
148152
project, err := opts.ToProject(nil)
149153
if err != nil {
150154
return err
@@ -155,7 +159,7 @@ func runServices(streams api.Streams, opts convertOptions) error {
155159
})
156160
}
157161

158-
func runVolumes(streams api.Streams, opts convertOptions) error {
162+
func runVolumes(streams api.Streams, opts configOptions) error {
159163
project, err := opts.ToProject(nil)
160164
if err != nil {
161165
return err
@@ -166,7 +170,7 @@ func runVolumes(streams api.Streams, opts convertOptions) error {
166170
return nil
167171
}
168172

169-
func runHash(streams api.Streams, opts convertOptions) error {
173+
func runHash(streams api.Streams, opts configOptions) error {
170174
var services []string
171175
if opts.hash != "*" {
172176
services = append(services, strings.Split(opts.hash, ",")...)
@@ -198,7 +202,7 @@ func runHash(streams api.Streams, opts convertOptions) error {
198202
return nil
199203
}
200204

201-
func runProfiles(streams api.Streams, opts convertOptions, services []string) error {
205+
func runProfiles(streams api.Streams, opts configOptions, services []string) error {
202206
set := map[string]struct{}{}
203207
project, err := opts.ToProject(services)
204208
if err != nil {
@@ -220,7 +224,7 @@ func runProfiles(streams api.Streams, opts convertOptions, services []string) er
220224
return nil
221225
}
222226

223-
func runConfigImages(streams api.Streams, opts convertOptions, services []string) error {
227+
func runConfigImages(streams api.Streams, opts configOptions, services []string) error {
224228
project, err := opts.ToProject(services)
225229
if err != nil {
226230
return err

0 commit comments

Comments
 (0)