diff --git a/cmd/compose/create.go b/cmd/compose/create.go index 915231fd9a7..aa7175b1e4a 100644 --- a/cmd/compose/create.go +++ b/cmd/compose/create.go @@ -110,6 +110,10 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe build = &bo } + if createOpts.AssumeYes { + backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt())) + } + backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) if err != nil { return err @@ -124,7 +128,6 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe Inherit: !createOpts.noInherit, Timeout: createOpts.GetTimeout(), QuietPull: createOpts.quietPull, - AssumeYes: createOpts.AssumeYes, }) } diff --git a/cmd/compose/publish.go b/cmd/compose/publish.go index d57e2a91506..becd162eeff 100644 --- a/cmd/compose/publish.go +++ b/cmd/compose/publish.go @@ -78,6 +78,9 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back return errors.New("cannot publish compose file with local includes") } + if opts.assumeYes { + backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt())) + } backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) if err != nil { return err @@ -87,6 +90,5 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back Application: opts.app, OCIVersion: api.OCIVersion(opts.ociVersion), WithEnvironment: opts.withEnvironment, - AssumeYes: opts.assumeYes, }) } diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 7b52792d4c3..6eb736a4e5d 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -278,7 +278,10 @@ func runUp( Inherit: !createOptions.noInherit, Timeout: createOptions.GetTimeout(), QuietPull: createOptions.quietPull, - AssumeYes: createOptions.AssumeYes, + } + + if createOptions.AssumeYes { + backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt())) } backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...) diff --git a/pkg/api/api.go b/pkg/api/api.go index ec800c6cc79..427520beb2b 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -231,8 +231,6 @@ type CreateOptions struct { Timeout *time.Duration // QuietPull makes the pulling process quiet QuietPull bool - // AssumeYes assume "yes" as answer to all prompts and run non-interactively - AssumeYes bool } // StartOptions group options of the Start API @@ -447,7 +445,6 @@ type PublishOptions struct { Application bool WithEnvironment bool - AssumeYes bool OCIVersion OCIVersion } diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index d475d9a9426..10ce5b0e638 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -195,6 +195,13 @@ func WithDryRun(s *composeService) error { type Prompt func(message string, defaultValue bool) (bool, error) +// AlwaysOkPrompt returns a Prompt implementation that always returns true without user interaction. +func AlwaysOkPrompt() Prompt { + return func(message string, defaultValue bool) (bool, error) { + return true, nil + } +} + // WithEventProcessor configure component to get notified on Compose operation and progress events. // Typically used to configure a progress UI func WithEventProcessor(bus progress.EventProcessor) Option { diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 07f1085ad62..0f61c78264f 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -93,7 +93,7 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt return err } - volumes, err := s.ensureProjectVolumes(ctx, project, options.AssumeYes) + volumes, err := s.ensureProjectVolumes(ctx, project) if err != nil { return err } @@ -150,13 +150,13 @@ func (s *composeService) ensureNetworks(ctx context.Context, project *types.Proj return networks, nil } -func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project, assumeYes bool) (map[string]string, error) { +func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project) (map[string]string, error) { ids := map[string]string{} for k, volume := range project.Volumes { volume.CustomLabels = volume.CustomLabels.Add(api.VolumeLabel, k) volume.CustomLabels = volume.CustomLabels.Add(api.ProjectLabel, project.Name) volume.CustomLabels = volume.CustomLabels.Add(api.VersionLabel, api.ComposeVersion) - id, err := s.ensureVolume(ctx, k, volume, project, assumeYes) + id, err := s.ensureVolume(ctx, k, volume, project) if err != nil { return nil, err } @@ -1529,7 +1529,7 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne } } -func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project, assumeYes bool) (string, error) { +func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project) (string, error) { inspected, err := s.apiClient().VolumeInspect(ctx, volume.Name) if err != nil { if !errdefs.IsNotFound(err) { @@ -1561,13 +1561,10 @@ func (s *composeService) ensureVolume(ctx context.Context, name string, volume t } actual, ok := inspected.Labels[api.ConfigHashLabel] if ok && actual != expected { - confirm := assumeYes - if !assumeYes { - msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name) - confirm, err = s.prompt(msg, false) - if err != nil { - return "", err - } + msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name) + confirm, err := s.prompt(msg, false) + if err != nil { + return "", err } if confirm { err = s.removeDivergedVolume(ctx, name, volume, project) diff --git a/pkg/compose/publish.go b/pkg/compose/publish.go index 15abce6f1e5..c1017bac201 100644 --- a/pkg/compose/publish.go +++ b/pkg/compose/publish.go @@ -297,9 +297,6 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp if ok, err := s.checkOnlyBuildSection(project); !ok || err != nil { return false, err } - if options.AssumeYes { - return true, nil - } bindMounts := s.checkForBindMount(project) if len(bindMounts) > 0 { b := strings.Builder{}