Skip to content

Commit 3658a06

Browse files
gloursndeloof
authored andcommitted
add AlwaysOkPrompt to replace 'AlwaysYes' current implementation'
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
1 parent 74a4ccd commit 3658a06

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

cmd/compose/create.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
110110
build = &bo
111111
}
112112

113+
if createOpts.AssumeYes {
114+
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
115+
}
116+
113117
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
114118
if err != nil {
115119
return err
@@ -124,7 +128,6 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
124128
Inherit: !createOpts.noInherit,
125129
Timeout: createOpts.GetTimeout(),
126130
QuietPull: createOpts.quietPull,
127-
AssumeYes: createOpts.AssumeYes,
128131
})
129132
}
130133

cmd/compose/publish.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back
7878
return errors.New("cannot publish compose file with local includes")
7979
}
8080

81+
if opts.assumeYes {
82+
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
83+
}
8184
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
8285
if err != nil {
8386
return err
@@ -87,6 +90,5 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back
8790
Application: opts.app,
8891
OCIVersion: api.OCIVersion(opts.ociVersion),
8992
WithEnvironment: opts.withEnvironment,
90-
AssumeYes: opts.assumeYes,
9193
})
9294
}

cmd/compose/up.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ func runUp(
278278
Inherit: !createOptions.noInherit,
279279
Timeout: createOptions.GetTimeout(),
280280
QuietPull: createOptions.quietPull,
281-
AssumeYes: createOptions.AssumeYes,
281+
}
282+
283+
if createOptions.AssumeYes {
284+
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
282285
}
283286

284287
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)

pkg/api/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ type CreateOptions struct {
231231
Timeout *time.Duration
232232
// QuietPull makes the pulling process quiet
233233
QuietPull bool
234-
// AssumeYes assume "yes" as answer to all prompts and run non-interactively
235-
AssumeYes bool
236234
}
237235

238236
// StartOptions group options of the Start API
@@ -447,7 +445,6 @@ type PublishOptions struct {
447445
Application bool
448446
WithEnvironment bool
449447

450-
AssumeYes bool
451448
OCIVersion OCIVersion
452449
}
453450

pkg/compose/compose.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ func WithDryRun(s *composeService) error {
195195

196196
type Prompt func(message string, defaultValue bool) (bool, error)
197197

198+
// AlwaysOkPrompt returns a Prompt implementation that always returns true without user interaction.
199+
func AlwaysOkPrompt() Prompt {
200+
return func(message string, defaultValue bool) (bool, error) {
201+
return true, nil
202+
}
203+
}
204+
198205
// WithEventProcessor configure component to get notified on Compose operation and progress events.
199206
// Typically used to configure a progress UI
200207
func WithEventProcessor(bus progress.EventProcessor) Option {

pkg/compose/create.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
9393
return err
9494
}
9595

96-
volumes, err := s.ensureProjectVolumes(ctx, project, options.AssumeYes)
96+
volumes, err := s.ensureProjectVolumes(ctx, project)
9797
if err != nil {
9898
return err
9999
}
@@ -150,13 +150,13 @@ func (s *composeService) ensureNetworks(ctx context.Context, project *types.Proj
150150
return networks, nil
151151
}
152152

153-
func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project, assumeYes bool) (map[string]string, error) {
153+
func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project) (map[string]string, error) {
154154
ids := map[string]string{}
155155
for k, volume := range project.Volumes {
156156
volume.CustomLabels = volume.CustomLabels.Add(api.VolumeLabel, k)
157157
volume.CustomLabels = volume.CustomLabels.Add(api.ProjectLabel, project.Name)
158158
volume.CustomLabels = volume.CustomLabels.Add(api.VersionLabel, api.ComposeVersion)
159-
id, err := s.ensureVolume(ctx, k, volume, project, assumeYes)
159+
id, err := s.ensureVolume(ctx, k, volume, project)
160160
if err != nil {
161161
return nil, err
162162
}
@@ -1529,7 +1529,7 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne
15291529
}
15301530
}
15311531

1532-
func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project, assumeYes bool) (string, error) {
1532+
func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project) (string, error) {
15331533
inspected, err := s.apiClient().VolumeInspect(ctx, volume.Name)
15341534
if err != nil {
15351535
if !errdefs.IsNotFound(err) {
@@ -1561,13 +1561,10 @@ func (s *composeService) ensureVolume(ctx context.Context, name string, volume t
15611561
}
15621562
actual, ok := inspected.Labels[api.ConfigHashLabel]
15631563
if ok && actual != expected {
1564-
confirm := assumeYes
1565-
if !assumeYes {
1566-
msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name)
1567-
confirm, err = s.prompt(msg, false)
1568-
if err != nil {
1569-
return "", err
1570-
}
1564+
msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name)
1565+
confirm, err := s.prompt(msg, false)
1566+
if err != nil {
1567+
return "", err
15711568
}
15721569
if confirm {
15731570
err = s.removeDivergedVolume(ctx, name, volume, project)

pkg/compose/publish.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp
297297
if ok, err := s.checkOnlyBuildSection(project); !ok || err != nil {
298298
return false, err
299299
}
300-
if options.AssumeYes {
301-
return true, nil
302-
}
303300
bindMounts := s.checkForBindMount(project)
304301
if len(bindMounts) > 0 {
305302
b := strings.Builder{}

0 commit comments

Comments
 (0)