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

Commit 82f35d1

Browse files
committed
Move progress writter into backend(s)
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent db30ef7 commit 82f35d1

File tree

23 files changed

+123
-118
lines changed

23 files changed

+123
-118
lines changed

aci/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ func (cs *aciComposeService) RunOneOffContainer(ctx context.Context, project *ty
227227
return 0, errdefs.ErrNotImplemented
228228
}
229229

230-
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
231-
return nil, errdefs.ErrNotImplemented
230+
func (cs *aciComposeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error {
231+
return errdefs.ErrNotImplemented
232232
}
233233

234234
func (cs *aciComposeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {

api/client/compose.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func (c *composeService) RunOneOffContainer(ctx context.Context, project *types.
8888
return 0, errdefs.ErrNotImplemented
8989
}
9090

91-
func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
92-
return nil, errdefs.ErrNotImplemented
91+
func (c *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) error {
92+
return errdefs.ErrNotImplemented
9393
}
9494

9595
func (c *composeService) Exec(ctx context.Context, project *types.Project, opts compose.RunOptions) (int, error) {

api/compose/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Service interface {
5959
// RunOneOffContainer creates a service oneoff container and starts its dependencies
6060
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
6161
// Remove executes the equivalent to a `compose rm`
62-
Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error)
62+
Remove(ctx context.Context, project *types.Project, options RemoveOptions) error
6363
// Exec executes a command in a running service container
6464
Exec(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
6565
// Copy copies a file/folder between a service container and the local filesystem
@@ -169,8 +169,9 @@ type PushOptions struct {
169169
IgnoreFailures bool
170170
}
171171

172-
// PullOptions group options of the Push API
172+
// PullOptions group options of the Pull API
173173
type PullOptions struct {
174+
Quiet bool
174175
IgnoreFailures bool
175176
}
176177

api/compose/proxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ServiceProxy struct {
4141
ConvertFn func(ctx context.Context, project *types.Project, options ConvertOptions) ([]byte, error)
4242
KillFn func(ctx context.Context, project *types.Project, options KillOptions) error
4343
RunOneOffContainerFn func(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
44-
RemoveFn func(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error)
44+
RemoveFn func(ctx context.Context, project *types.Project, options RemoveOptions) error
4545
ExecFn func(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
4646
CopyFn func(ctx context.Context, project *types.Project, opts CopyOptions) error
4747
PauseFn func(ctx context.Context, project string, options PauseOptions) error
@@ -252,9 +252,9 @@ func (s *ServiceProxy) RunOneOffContainer(ctx context.Context, project *types.Pr
252252
}
253253

254254
//Remove implements Service interface
255-
func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, options RemoveOptions) ([]string, error) {
255+
func (s *ServiceProxy) Remove(ctx context.Context, project *types.Project, options RemoveOptions) error {
256256
if s.RemoveFn == nil {
257-
return nil, errdefs.ErrNotImplemented
257+
return errdefs.ErrNotImplemented
258258
}
259259
for _, i := range s.interceptors {
260260
i(ctx, project)

cli/cmd/compose/build.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/docker/compose-cli/api/compose"
28-
"github.com/docker/compose-cli/api/progress"
2928
)
3029

3130
type buildOptions struct {
@@ -88,14 +87,11 @@ func runBuild(ctx context.Context, backend compose.Service, opts buildOptions, s
8887
return err
8988
}
9089

91-
err = progress.Run(ctx, func(ctx context.Context) error {
92-
return backend.Build(ctx, project, compose.BuildOptions{
93-
Pull: opts.pull,
94-
Progress: opts.progress,
95-
Args: types.NewMappingWithEquals(opts.args),
96-
NoCache: opts.noCache,
97-
Quiet: opts.quiet,
98-
})
90+
return backend.Build(ctx, project, compose.BuildOptions{
91+
Pull: opts.pull,
92+
Progress: opts.progress,
93+
Args: types.NewMappingWithEquals(opts.args),
94+
NoCache: opts.noCache,
95+
Quiet: opts.quiet,
9996
})
100-
return err
10197
}

cli/cmd/compose/pause.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/docker/compose-cli/api/compose"
25-
"github.com/docker/compose-cli/api/progress"
2625
)
2726

2827
type pauseOptions struct {
@@ -49,12 +48,9 @@ func runPause(ctx context.Context, backend compose.Service, opts pauseOptions, s
4948
return err
5049
}
5150

52-
err = progress.Run(ctx, func(ctx context.Context) error {
53-
return backend.Pause(ctx, project, compose.PauseOptions{
54-
Services: services,
55-
})
51+
return backend.Pause(ctx, project, compose.PauseOptions{
52+
Services: services,
5653
})
57-
return err
5854
}
5955

6056
type unpauseOptions struct {
@@ -81,9 +77,7 @@ func runUnPause(ctx context.Context, backend compose.Service, opts unpauseOption
8177
return err
8278
}
8379

84-
return progress.Run(ctx, func(ctx context.Context) error {
85-
return backend.UnPause(ctx, project, compose.PauseOptions{
86-
Services: services,
87-
})
80+
return backend.UnPause(ctx, project, compose.PauseOptions{
81+
Services: services,
8882
})
8983
}

cli/cmd/compose/pull.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/docker/compose-cli/api/compose"
28-
"github.com/docker/compose-cli/api/progress"
2928
"github.com/docker/compose-cli/utils"
3029
)
3130

@@ -86,15 +85,8 @@ func runPull(ctx context.Context, backend compose.Service, opts pullOptions, ser
8685
project.Services = enabled
8786
}
8887

89-
apiOpts := compose.PullOptions{
88+
return backend.Pull(ctx, project, compose.PullOptions{
89+
Quiet: opts.quiet,
9090
IgnoreFailures: opts.ignorePullFailures,
91-
}
92-
93-
if opts.quiet {
94-
return backend.Pull(ctx, project, apiOpts)
95-
}
96-
97-
return progress.Run(ctx, func(ctx context.Context) error {
98-
return backend.Pull(ctx, project, apiOpts)
9991
})
10092
}

cli/cmd/compose/push.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/spf13/cobra"
2323

2424
"github.com/docker/compose-cli/api/compose"
25-
"github.com/docker/compose-cli/api/progress"
2625
)
2726

2827
type pushOptions struct {
@@ -54,9 +53,7 @@ func runPush(ctx context.Context, backend compose.Service, opts pushOptions, ser
5453
return err
5554
}
5655

57-
return progress.Run(ctx, func(ctx context.Context) error {
58-
return backend.Push(ctx, project, compose.PushOptions{
59-
IgnoreFailures: opts.Ignorefailures,
60-
})
56+
return backend.Push(ctx, project, compose.PushOptions{
57+
IgnoreFailures: opts.Ignorefailures,
6158
})
6259
}

cli/cmd/compose/remove.go

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ package compose
1818

1919
import (
2020
"context"
21-
"fmt"
22-
"strings"
2321

2422
"github.com/docker/compose-cli/api/compose"
25-
"github.com/docker/compose-cli/api/progress"
26-
"github.com/docker/compose-cli/utils/prompt"
27-
2823
"github.com/spf13/cobra"
2924
)
3025

@@ -69,46 +64,12 @@ func runRemove(ctx context.Context, backend compose.Service, opts removeOptions,
6964
}
7065

7166
if opts.stop {
72-
err = progress.Run(ctx, func(ctx context.Context) error {
73-
return backend.Stop(ctx, project, compose.StopOptions{
74-
Services: services,
75-
})
67+
return backend.Stop(ctx, project, compose.StopOptions{
68+
Services: services,
7669
})
77-
if err != nil {
78-
return err
79-
}
8070
}
8171

82-
resources, err := backend.Remove(ctx, project, compose.RemoveOptions{
83-
DryRun: true,
72+
return backend.Remove(ctx, project, compose.RemoveOptions{
8473
Services: services,
8574
})
86-
if err != nil {
87-
return err
88-
}
89-
90-
if len(resources) == 0 {
91-
fmt.Println("No stopped containers")
92-
return nil
93-
}
94-
msg := fmt.Sprintf("Going to remove %s", strings.Join(resources, ", "))
95-
if opts.force {
96-
fmt.Println(msg)
97-
} else {
98-
confirm, err := prompt.User{}.Confirm(msg, false)
99-
if err != nil {
100-
return err
101-
}
102-
if !confirm {
103-
return nil
104-
}
105-
}
106-
107-
return progress.Run(ctx, func(ctx context.Context) error {
108-
_, err := backend.Remove(ctx, project, compose.RemoveOptions{
109-
Volumes: opts.volumes,
110-
Force: opts.force,
111-
})
112-
return err
113-
})
11475
}

cli/cmd/compose/restart.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/spf13/cobra"
2424

2525
"github.com/docker/compose-cli/api/compose"
26-
"github.com/docker/compose-cli/api/progress"
2726
)
2827

2928
type restartOptions struct {
@@ -55,10 +54,8 @@ func runRestart(ctx context.Context, backend compose.Service, opts restartOption
5554
}
5655

5756
timeout := time.Duration(opts.timeout) * time.Second
58-
return progress.Run(ctx, func(ctx context.Context) error {
59-
return backend.Restart(ctx, project, compose.RestartOptions{
60-
Timeout: &timeout,
61-
Services: services,
62-
})
57+
return backend.Restart(ctx, project, compose.RestartOptions{
58+
Timeout: &timeout,
59+
Services: services,
6360
})
6461
}

0 commit comments

Comments
 (0)