Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 21e2f5c

Browse files
committed
use interceptor to implement ACI-specific flags
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 62af4e0 commit 21e2f5c

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

cli/cmd/compose/up.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ type composeOptions struct {
4545
*projectOptions
4646
Build bool
4747
noBuild bool
48-
// ACI only
49-
DomainName string
5048
}
5149

5250
type upOptions struct {
@@ -186,8 +184,6 @@ func upCommand(p *projectOptions, contextType string, backend compose.Service) *
186184
flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.")
187185

188186
switch contextType {
189-
case store.AciContextType:
190-
flags.StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
191187
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
192188
flags.BoolVar(&opts.forceRecreate, "force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
193189
flags.BoolVar(&opts.noRecreate, "no-recreate", false, "If containers already exist, don't recreate them. Incompatible with --force-recreate.")
@@ -360,10 +356,6 @@ func setup(opts composeOptions, services []string) (*types.Project, error) {
360356
return nil, err
361357
}
362358

363-
if opts.DomainName != "" {
364-
// arbitrarily set the domain name on the first service ; ACI backend will expose the entire project
365-
project.Services[0].DomainName = opts.DomainName
366-
}
367359
if opts.Build {
368360
for i, service := range project.Services {
369361
service.PullPolicy = types.PullPolicyBuild

cli/main.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ import (
2828
"syscall"
2929
"time"
3030

31+
"github.com/compose-spec/compose-go/types"
3132
"github.com/docker/cli/cli"
3233
"github.com/pkg/errors"
3334
"github.com/sirupsen/logrus"
3435
"github.com/spf13/cobra"
3536

3637
"github.com/docker/compose-cli/api/backend"
38+
api "github.com/docker/compose-cli/api/compose"
3739
"github.com/docker/compose-cli/api/config"
3840
apicontext "github.com/docker/compose-cli/api/context"
3941
"github.com/docker/compose-cli/api/context/store"
@@ -223,7 +225,14 @@ func main() {
223225

224226
if ctype != store.DefaultContextType {
225227
// On default context, "compose" is implemented by CLI Plugin
226-
root.AddCommand(compose.RootCommand(ctype, service.ComposeService()))
228+
proxy := api.NewServiceProxy().WithService(service.ComposeService())
229+
command := compose.RootCommand(ctype, proxy)
230+
231+
if ctype == store.AciContextType {
232+
customizeCliForACI(command, proxy)
233+
}
234+
235+
root.AddCommand(command)
227236
}
228237

229238
if err = root.ExecuteContext(ctx); err != nil {
@@ -232,6 +241,22 @@ func main() {
232241
metrics.Track(ctype, os.Args[1:], metrics.SuccessStatus)
233242
}
234243

244+
func customizeCliForACI(command *cobra.Command, proxy *api.ServiceProxy) {
245+
var domainName string
246+
for _, c := range command.Commands() {
247+
if c.Name() == "up" {
248+
c.Flags().StringVar(&domainName, "domainname", "", "Container NIS domain name")
249+
proxy.WithInterceptor(func(ctx context.Context, project *types.Project) {
250+
if domainName != "" {
251+
// arbitrarily set the domain name on the first service ; ACI backend will expose the entire project
252+
project.Services[0].DomainName = domainName
253+
}
254+
255+
})
256+
}
257+
}
258+
}
259+
235260
func getBackend(ctype string, configDir string, opts cliopts.GlobalOpts) (backend.Service, error) {
236261
switch ctype {
237262
case store.DefaultContextType, store.LocalContextType:

0 commit comments

Comments
 (0)